From f50ab981f788d7fb0c507758857d4a190d3d8fb7 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 25 Jul 2020 18:32:49 +0100 Subject: [PATCH] drive: stop using root_folder_id as a cache #4419 Previous to this change rclone cached the looked up root_folder_id in the root_folder_id config variable. This has caused a lot of confusion and a few attempts at workarounds and ultimately was a mistake. This reverts rclone attempting to cache anything in root_folder_id and returns that variable to be entirely user modified. It gives a little hint in the debug that rclone could be sped up slightly by setting it, but it is up to the user to think about whether that would be OK or not. Google drive root '': root_folder_id = "XXX" - save this in the config to speed up startup It does not change root_folder_id itself, leaving this to the user. See: https://forum.rclone.org/t/rclone-gdrive-no-longer-returning-anything/17215 --- backend/drive/drive.go | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 2ef55f0fe..d651e567e 100755 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -224,9 +224,6 @@ Leave blank normally. Fill in to access "Computers" folders (see docs), or for rclone to use a non root folder as its starting point. - -Note that if this is blank, the first time rclone runs it will fill it -in with the ID of the root folder. `, }, { Name: "service_account_file", @@ -350,12 +347,9 @@ 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. - -Note that if this is used then "root_folder_id" will be ignored. -`, + Name: "impersonate", + Default: "", + Help: `Impersonate this user when using a service account.`, Advanced: true, }, { Name: "alternate_export", @@ -1112,25 +1106,15 @@ func NewFs(name, path string, m configmap.Mapper) (fs.Fs, error) { return nil, err } - // 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 f.opt.RootFolderID != "" && f.opt.RootFolderID != "appDataFolder" && f.opt.Impersonate != "" { - fs.Logf(f, "Ignoring cached root_folder_id when using --drive-impersonate") - f.opt.RootFolderID = "" - } - - // set root folder for a team drive or query the user root folder + // Set the root folder ID if f.opt.RootFolderID != "" { - // override root folder if set or cached in the config and not impersonating + // use root_folder ID if set f.rootFolderID = f.opt.RootFolderID } else if f.isTeamDrive { + // otherwise use team_drive if set f.rootFolderID = f.opt.TeamDriveID } else { - // Look up the root ID and cache it in the config + // otherwise look up the actual root ID rootID, err := f.getRootID() if err != nil { if gerr, ok := errors.Cause(err).(*googleapi.Error); ok && gerr.Code == 404 { @@ -1142,10 +1126,7 @@ func NewFs(name, path string, m configmap.Mapper) (fs.Fs, error) { } } f.rootFolderID = rootID - // Don't cache the root folder ID if impersonating - if f.opt.Impersonate == "" { - m.Set("root_folder_id", rootID) - } + fs.Debugf(f, "root_folder_id = %q - save this in the config to speed up startup", rootID) } f.dirCache = dircache.New(f.root, f.rootFolderID, f)