From 06ffd4882d2e7467415221302e0a8a429ddbfe92 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 28 Jan 2022 17:17:35 +0000 Subject: [PATCH] onedrive: add --onedrive-root-folder-id flag #5948 This is to navigate to difficult to find folders in onedrive. --- backend/onedrive/onedrive.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index 14269f443..8052b33a1 100644 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -140,6 +140,15 @@ Note that the chunks will be buffered into memory.`, Help: "The type of the drive (" + driveTypePersonal + " | " + driveTypeBusiness + " | " + driveTypeSharepoint + ").", Default: "", Advanced: true, + }, { + Name: "root_folder_id", + Help: `ID of the root folder. + +This isn't normally needed, but in special circumstances you might +know the folder ID that you wish to access but not be able to get +there through a path traversal. +`, + Advanced: true, }, { Name: "disable_site_permission", Help: `Disable the request for Sites.Read.All permission. @@ -547,6 +556,7 @@ type Options struct { ChunkSize fs.SizeSuffix `config:"chunk_size"` DriveID string `config:"drive_id"` DriveType string `config:"drive_type"` + RootFolderID string `config:"root_folder_id"` DisableSitePermission bool `config:"disable_site_permission"` ExposeOneNoteFiles bool `config:"expose_onenote_files"` ServerSideAcrossConfigs bool `config:"server_side_across_configs"` @@ -852,15 +862,19 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e }) // Get rootID - rootInfo, _, err := f.readMetaDataForPath(ctx, "") - if err != nil { - return nil, fmt.Errorf("failed to get root: %w", err) + var rootID = opt.RootFolderID + if rootID == "" { + rootInfo, _, err := f.readMetaDataForPath(ctx, "") + if err != nil { + return nil, fmt.Errorf("failed to get root: %w", err) + } + rootID = rootInfo.GetID() } - if rootInfo.GetID() == "" { + if rootID == "" { return nil, errors.New("failed to get root: ID was empty") } - f.dirCache = dircache.New(root, rootInfo.GetID(), f) + f.dirCache = dircache.New(root, rootID, f) // Find the current root err = f.dirCache.FindRoot(ctx, false) @@ -868,7 +882,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e // Assume it is a file newRoot, remote := dircache.SplitPath(root) tempF := *f - tempF.dirCache = dircache.New(newRoot, rootInfo.ID, &tempF) + tempF.dirCache = dircache.New(newRoot, rootID, &tempF) tempF.root = newRoot // Make new Fs which is the parent err = tempF.dirCache.FindRoot(ctx, false)