Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

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

Nick Craig-Wooddfc7215bf9b7
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
})