From dfc7215bf9b7840f438d006bf7b399974f5ebf42 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 6 Mar 2020 15:31:23 +0000 Subject: [PATCH] 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. --- backend/drive/drive.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 55ad5a732..feee84a69 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -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 })