cmount: always supply stat information in Readdir

It is cheap to make the stat information here - we give FUSE a file
type to look at least.
This commit is contained in:
Nick Craig-Wood 2020-07-05 11:28:30 +01:00
parent 306a3e0cd7
commit d73a418a55
2 changed files with 7 additions and 19 deletions

View file

@ -231,7 +231,7 @@ func (fsys *FS) Readdir(dirPath string,
// for getattr (but FUSE only looks at st_ino and the // for getattr (but FUSE only looks at st_ino and the
// file-type bits of st_mode). // file-type bits of st_mode).
// //
// FIXME If you call host.SetCapReaddirPlus() then WinFsp will // We have called host.SetCapReaddirPlus() so WinFsp will
// use the full stat information - a Useful optimization on // use the full stat information - a Useful optimization on
// Windows. // Windows.
// //
@ -250,14 +250,11 @@ func (fsys *FS) Readdir(dirPath string,
fs.Errorf(dirPath, "Name too long (%d bytes) for FUSE, skipping: %s", len(name), name) fs.Errorf(dirPath, "Name too long (%d bytes) for FUSE, skipping: %s", len(name), name)
continue continue
} }
if usingReaddirPlus { // We have called host.SetCapReaddirPlus() so supply the stat information
// We have called host.SetCapReaddirPlus() so supply the stat information // It is very cheap at this point so supply it regardless of OS capabilities
var stat fuse.Stat_t var stat fuse.Stat_t
_ = fsys.stat(node, &stat) // not capable of returning an error _ = fsys.stat(node, &stat) // not capable of returning an error
fill(name, &stat, 0) fill(name, &stat, 0)
} else {
fill(name, nil, 0)
}
} }
} }
itemsRead = len(items) itemsRead = len(items)

View file

@ -21,13 +21,6 @@ import (
"github.com/rclone/rclone/vfs" "github.com/rclone/rclone/vfs"
) )
const (
// SetCapReaddirPlus informs the host that the hosted file system has the readdir-plus
// capability [Windows only]. A file system that has the readdir-plus capability can send
// full stat information during Readdir, thus avoiding extraneous Getattr calls.
usingReaddirPlus = runtime.GOOS == "windows"
)
func init() { func init() {
name := "cmount" name := "cmount"
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
@ -146,9 +139,7 @@ func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (<-chan error
// Create underlying FS // Create underlying FS
fsys := NewFS(VFS) fsys := NewFS(VFS)
host := fuse.NewFileSystemHost(fsys) host := fuse.NewFileSystemHost(fsys)
if usingReaddirPlus { host.SetCapReaddirPlus(true) // only works on Windows
host.SetCapReaddirPlus(true)
}
host.SetCapCaseInsensitive(f.Features().CaseInsensitive) host.SetCapCaseInsensitive(f.Features().CaseInsensitive)
// Create options // Create options