drive: fix duplicate items when using --drive-shared-with-me #4018

Before this change shared with me items with multiple parents (ie most
of them that aren't in the root) would appear twice in the directory
listings.

This fixes the problem by doing an early exit for shared with me
items.
This commit is contained in:
Nick Craig-Wood 2020-03-06 15:31:23 +00:00
parent 38e59ebdf3
commit dfc7215bf9
1 changed files with 9 additions and 0 deletions

View File

@ -1597,6 +1597,7 @@ func (f *Fs) listRRunner(ctx context.Context, wg *sync.WaitGroup, in <-chan list
}
for _, parent := range item.Parents {
var i int
earlyExit := false
// If only one item in paths then no need to search for the ID
// assuming google drive is doing its job properly.
//
@ -1606,6 +1607,9 @@ func (f *Fs) listRRunner(ctx context.Context, wg *sync.WaitGroup, in <-chan list
// - 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
// items at root can have more than one parent so we need to put
// the item in just once.
earlyExit = true
} else {
// only handle parents that are in the requested dirs list if not at root
i = sort.SearchStrings(dirs, parent)
@ -1625,6 +1629,11 @@ func (f *Fs) listRRunner(ctx context.Context, wg *sync.WaitGroup, in <-chan list
iErr = err
return true
}
// If didn't check parents then insert only once
if earlyExit {
break
}
}
return false
})