From ac7cfcc848727ccb0d6c1314b3c1320522e4e652 Mon Sep 17 00:00:00 2001 From: phatlc Date: Tue, 11 Aug 2026 23:17:37 +0700 Subject: [PATCH] dropbox: fix shared folder mount for roots nested more than one level deep In shared_folders mode NewFs derived the shared folder name with path.Dir(f.root), which returns the parent path rather than the first path component. For a root like "SharedFolder/subdir/deeper" this yielded "SharedFolder/subdir", which findSharedFolder cannot match, so NewFs failed with ErrorDirNotFound. Use the first path component of the root, as the shared_folders option documents, so deeply nested roots mount. Fixes #9705 --- backend/dropbox/dropbox.go | 15 +++++++++------ backend/dropbox/dropbox_internal_test.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/backend/dropbox/dropbox.go b/backend/dropbox/dropbox.go index 826dee6dd..fa1d125bf 100644 --- a/backend/dropbox/dropbox.go +++ b/backend/dropbox/dropbox.go @@ -634,13 +634,8 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e return f, nil // our root it empty so we probably want to list shared folders } - dir := path.Dir(f.root) - if dir == "." { - dir = f.root - } - // root is not empty so we have find the right shared folder if it exists - id, err := f.findSharedFolder(ctx, dir) + id, err := f.findSharedFolder(ctx, sharedFolderName(f.root)) if err != nil { // if we didn't find the specified shared folder we have to bail out here return nil, err @@ -948,6 +943,14 @@ func (f *Fs) listSharedFolders(ctx context.Context, callback func(fs.DirEntry) e return nil } +// sharedFolderName returns the shared folder name in root, which is its first +// path component. root must be the trimmed root as produced by setRoot (no +// leading slash). +func sharedFolderName(root string) string { + name, _, _ := strings.Cut(root, "/") + return name +} + // findSharedFolder find the id for a given shared folder name // somewhat annoyingly there is no endpoint to query a shared folder by it's name // so our only option is to iterate over all shared folders diff --git a/backend/dropbox/dropbox_internal_test.go b/backend/dropbox/dropbox_internal_test.go index c6140af17..e96228a4d 100644 --- a/backend/dropbox/dropbox_internal_test.go +++ b/backend/dropbox/dropbox_internal_test.go @@ -188,6 +188,21 @@ func TestInternalCheckPathLength(t *testing.T) { } } +func TestInternalSharedFolderName(t *testing.T) { + for _, test := range []struct { + root string + want string + }{ + {root: "", want: ""}, + {root: "SharedFolder", want: "SharedFolder"}, + {root: "SharedFolder/subdir", want: "SharedFolder"}, + {root: "SharedFolder/subdir/deeper", want: "SharedFolder"}, + {root: "SharedFolder/subdir/deeper/deepest", want: "SharedFolder"}, + } { + assert.Equal(t, test.want, sharedFolderName(test.root), test.root) + } +} + func TestPaperExportRemote(t *testing.T) { ctx := context.Background() info := &files.FileMetadata{