From 37308832b1bcf0b8cfc8f68965aea7df4914d896 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 17 Jun 2020 11:58:01 +0100 Subject: [PATCH] drive: fix --drive-impersonate with cached root_folder_id Before this fix rclone v1.51 and 1.52 would incorrectly use the cached root_folder_id when the --drive-impersonate flag was in use. This meant that rclone could be looking up the wrong directory ID with unpredictable results - usually all files apparently being missing. This fix makes rclone look up the root_folder_id always when using --drive-impersonate. It does this by clearing the root_folder_id and making a NOTICE message that it is ignoring the cached value. It also stops rclone caching the root_folder_id when using --drive-impersonate. See: https://forum.rclone.org/t/rclone-gdrive-no-longer-returning-anything/17215 --- backend/drive/drive.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 7c0a9c457..58909299f 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -349,9 +349,12 @@ date is used.`, Help: "Size of listing chunk 100-1000. 0 to disable.", Advanced: true, }, { - Name: "impersonate", - Default: "", - Help: "Impersonate this user when using a service account.", + Name: "impersonate", + Default: "", + Help: `Impersonate this user when using a service account. + +Note that if this is used then "root_folder_id" will be ignored. +`, Advanced: true, }, { Name: "alternate_export", @@ -1118,9 +1121,20 @@ func NewFs(name, path string, m configmap.Mapper) (fs.Fs, error) { } } + // If impersonating warn about root_folder_id if set and unset it + // + // This is because rclone v1.51 and v1.52 cached root_folder_id when + // using impersonate which they shouldn't have done. It is possible + // someone is using impersonate and root_folder_id in which case this + // breaks their workflow. There isn't an easy way around that. + if opt.RootFolderID != "" && opt.Impersonate != "" { + fs.Logf(f, "Ignoring cached root_folder_id when using --drive-impersonate") + opt.RootFolderID = "" + } + // set root folder for a team drive or query the user root folder if opt.RootFolderID != "" { - // override root folder if set or cached in the config + // override root folder if set or cached in the config and not impersonating f.rootFolderID = opt.RootFolderID } else if f.isTeamDrive { f.rootFolderID = f.opt.TeamDriveID @@ -1137,7 +1151,10 @@ func NewFs(name, path string, m configmap.Mapper) (fs.Fs, error) { } } f.rootFolderID = rootID - m.Set("root_folder_id", rootID) + // Don't cache the root folder ID if impersonating + if opt.Impersonate == "" { + m.Set("root_folder_id", rootID) + } } f.dirCache = dircache.New(root, f.rootFolderID, f)