From 4453fa4ba64f6729e99098269d441a207bc2ae08 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 4 Jan 2020 12:59:05 +0000 Subject: [PATCH] drive: fix --fast-list when using appDataFolder In listings if the ID `appDataFolder` is used to list a directory the parents of the items returned have the actual ID instead the alias `appDataFolder`. This confused the ListR routine into ignoring all these items. This change makes the listing routine accept all parent IDs returned if there was only one ID in the query. This fixes the `appDataFolder` problem. This means we are relying on Google Drive to only return the items we asked for which is probably OK. Fixes #3851 --- backend/drive/drive.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index a12c2f924..a84b46c35 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -1546,15 +1546,23 @@ func (f *Fs) listRRunner(ctx context.Context, wg *sync.WaitGroup, in <-chan list listRSlices{dirs, paths}.Sort() var iErr error _, err := f.list(ctx, dirs, "", false, false, false, func(item *drive.File) bool { - // shared with me items have no parents when at the root - if f.opt.SharedWithMe && len(item.Parents) == 0 && len(paths) == 1 && paths[0] == "" { - item.Parents = dirs - } for _, parent := range item.Parents { - // only handle parents that are in the requested dirs list - i := sort.SearchStrings(dirs, parent) - if i == len(dirs) || dirs[i] != parent { - continue + var i int + // If only one item in paths then no need to search for the ID + // assuming google drive is doing its job properly. + // + // Note that we at the root when len(paths) == 1 && paths[0] == "" + if len(paths) == 1 { + // don't check parents at root because + // - shared with me items have no parents at the root + // - if using a root alias, eg "root" or "appDataFolder" the ID won't match + i = 0 + } else { + // only handle parents that are in the requested dirs list if not at root + i = sort.SearchStrings(dirs, parent) + if i == len(dirs) || dirs[i] != parent { + continue + } } remote := path.Join(paths[i], item.Name) entry, err := f.itemToDirEntry(remote, item)