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
This commit is contained in:
Nick Craig-Wood 2020-01-04 12:59:05 +00:00
parent 540fd3f173
commit 4453fa4ba6

View File

@ -1546,15 +1546,23 @@ func (f *Fs) listRRunner(ctx context.Context, wg *sync.WaitGroup, in <-chan list
listRSlices{dirs, paths}.Sort() listRSlices{dirs, paths}.Sort()
var iErr error var iErr error
_, err := f.list(ctx, dirs, "", false, false, false, func(item *drive.File) bool { _, 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 { for _, parent := range item.Parents {
// only handle parents that are in the requested dirs list var i int
i := sort.SearchStrings(dirs, parent) // If only one item in paths then no need to search for the ID
if i == len(dirs) || dirs[i] != parent { // assuming google drive is doing its job properly.
continue //
// 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) remote := path.Join(paths[i], item.Name)
entry, err := f.itemToDirEntry(remote, item) entry, err := f.itemToDirEntry(remote, item)