Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cmount: fix macOS losing directory contents #4393

Nick Craig-Wood4ac662d144c0
diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go
index 883bbf069..d3f992514 100644
--- a/cmd/cmount/fs.go
+++ b/cmd/cmount/fs.go
@@ -217,12 +217,18 @@ func (fsys *FS) Readdir(dirPath string,
itemsRead := -1
defer log.Trace(dirPath, "ofst=%d, fh=0x%X", ofst, fh)("items=%d, errc=%d", &itemsRead, &errc)
- node, errc := fsys.getHandle(fh)
+ dir, errc := fsys.lookupDir(dirPath)
if errc != 0 {
return errc
}
- items, err := node.Readdir(-1)
+ // We can't seek in directories and FUSE should know that so
+ // return an error if ofst is ever set.
+ if ofst > 0 {
+ return -fuse.ESPIPE
+ }
+
+ nodes, err := dir.ReadDirAll()
if err != nil {
return translateError(err)
}
@@ -242,22 +248,19 @@ func (fsys *FS) Readdir(dirPath string,
// directory is read in a single readdir operation.
fill(".", nil, 0)
fill("..", nil, 0)
- for _, item := range items {
- node, ok := item.(vfs.Node)
- if ok {
- name := node.Name()
- if len(name) > mountlib.MaxLeafSize {
- fs.Errorf(dirPath, "Name too long (%d bytes) for FUSE, skipping: %s", len(name), name)
- continue
- }
- // 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
- _ = fsys.stat(node, &stat) // not capable of returning an error
- fill(name, &stat, 0)
+ for _, node := range nodes {
+ name := node.Name()
+ if len(name) > mountlib.MaxLeafSize {
+ fs.Errorf(dirPath, "Name too long (%d bytes) for FUSE, skipping: %s", len(name), name)
+ continue
}
+ // 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
+ _ = fsys.stat(node, &stat) // not capable of returning an error
+ fill(name, &stat, 0)
}
- itemsRead = len(items)
+ itemsRead = len(nodes)
return 0
}