From 78edafcaac0f4f73e92355d509f4f7aee84e4125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Sat, 2 Jan 2016 19:47:05 +0100 Subject: [PATCH] drive: add `--drive-auth-owner-only` to only consider files owned by the user. --- docs/content/drive.md | 5 +++++ drive/drive.go | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/content/drive.md b/docs/content/drive.md index 87ea0f234..c7db53e16 100644 --- a/docs/content/drive.md +++ b/docs/content/drive.md @@ -127,6 +127,11 @@ File size cutoff for switching to chunked upload. Default is 256kB. Send files to the trash instead of deleting permanently. Defaults to off, namely deleting files permanently. +#### --drive-auth-owner-only #### + +Only consider files owned by the authenticated user. Requires +that --drive-full-list=true (default). + ### Limitations ### Drive has quite a lot of rate limiting. This causes rclone to be diff --git a/drive/drive.go b/drive/drive.go index 59a379aa4..8c1d1fa43 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -43,8 +43,9 @@ const ( // Globals var ( // Flags - driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.") - driveUseTrash = pflag.BoolP("drive-use-trash", "", false, "Send files to the trash instead of deleting permanently.") + driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.") + driveAuthOwnerOnly = pflag.BoolP("drive-auth-owner-only", "", false, "Only consider files owned by the authenticated user. Requires drive-full-list.") + driveUseTrash = pflag.BoolP("drive-use-trash", "", false, "Send files to the trash instead of deleting permanently.") // chunkSize is the size of the chunks created during a resumable upload and should be a power of two. // 1<<18 is the minimum size supported by the Google uploader, and there is no maximum. chunkSize = fs.SizeSuffix(256 * 1024) @@ -400,6 +401,16 @@ func (f *Fs) listDirRecursive(dirID string, path string, out fs.ObjectsChan) err return nil } +// isAuthOwned checks if any of the item owners is the authenticated owner +func isAuthOwned(item *drive.File) bool { + for _, owner := range item.Owners { + if owner.IsAuthenticatedUser { + return true + } + } + return false +} + // Path should be directory path either "" or "path/" // // List the directory using a full listing and filtering out unwanted @@ -420,6 +431,9 @@ func (f *Fs) listDirFull(dirID string, path string, out fs.ObjectsChan) error { if directory != "" { path = directory + "/" + path } + if *driveAuthOwnerOnly && !isAuthOwned(item) { + return + } if item.MimeType == driveFolderType { // Put the directory into the dircache f.dirCache.Put(path, item.Id)