From 39d09c04a2e357882bfa43a3b1a3a5c7ff07ff50 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 19 Jul 2017 14:35:58 +0100 Subject: [PATCH] drive: Make --drive-trashed-only show all directories - fixes #1524 Without showing all directories it doesn't show trashed files which are in an untrashed directory. This isn't an ideal fix, but it makes the feature useable. --- docs/content/drive.md | 3 ++- drive/drive.go | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/content/drive.md b/docs/content/drive.md index 21f8aea3e..5081e0519 100644 --- a/docs/content/drive.md +++ b/docs/content/drive.md @@ -256,7 +256,8 @@ Skip google documents in all listings. If given, gdocs practically become invisi #### --drive-trashed-only #### -Only show files that are in the trash +Only show files that are in the trash. This will show trashed files +in their original directory structure. #### --drive-upload-cutoff=SIZE #### diff --git a/drive/drive.go b/drive/drive.go index 015fddb3c..9ec3f0dee 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -216,7 +216,11 @@ type listFn func(*drive.File) bool func (f *Fs) list(dirID string, title string, directoriesOnly bool, filesOnly bool, includeAll bool, fn listFn) (found bool, err error) { var query []string if !includeAll { - query = append(query, "trashed="+strconv.FormatBool(*driveTrashedOnly)) + q := "trashed=" + strconv.FormatBool(*driveTrashedOnly) + if *driveTrashedOnly { + q = fmt.Sprintf("(mimeType='%s' or %s)", driveFolderType, q) + } + query = append(query, q) } // Search with sharedWithMe will always return things listed in "Shared With Me" (without any parents) // We must not filter with parent when we try list "ROOT" with drive-shared-with-me @@ -241,10 +245,10 @@ func (f *Fs) list(dirID string, title string, directoriesOnly bool, filesOnly bo if filesOnly { query = append(query, fmt.Sprintf("mimeType!='%s'", driveFolderType)) } - // fmt.Printf("list Query = %q\n", query) list := f.svc.Files.List() if len(query) > 0 { list = list.Q(strings.Join(query, " and ")) + // fmt.Printf("list Query = %q\n", query) } if *driveListChunk > 0 { list = list.MaxResults(*driveListChunk)