onedrive: implement --onedrive-server-side-across-configs - fixes #4058

This commit is contained in:
Nick Craig-Wood 2020-03-15 12:07:46 +00:00
parent 37d5e75a56
commit 77e94be280

View File

@ -252,6 +252,16 @@ delete OneNote files or otherwise want them to show up in directory
listing, set this option.`, listing, set this option.`,
Default: false, Default: false,
Advanced: true, Advanced: true,
}, {
Name: "server_side_across_configs",
Default: false,
Help: `Allow server side operations (eg copy) to work across different onedrive configs.
This can be useful if you wish to do a server side copy between two
different Onedrives. Note that this isn't enabled by default
because it isn't easy to tell if it will work between any two
configurations.`,
Advanced: true,
}, { }, {
Name: config.ConfigEncoding, Name: config.ConfigEncoding,
Help: config.ConfigEncodingHelp, Help: config.ConfigEncodingHelp,
@ -304,11 +314,12 @@ listing, set this option.`,
// Options defines the configuration for this backend // Options defines the configuration for this backend
type Options struct { type Options struct {
ChunkSize fs.SizeSuffix `config:"chunk_size"` ChunkSize fs.SizeSuffix `config:"chunk_size"`
DriveID string `config:"drive_id"` DriveID string `config:"drive_id"`
DriveType string `config:"drive_type"` DriveType string `config:"drive_type"`
ExposeOneNoteFiles bool `config:"expose_onenote_files"` ExposeOneNoteFiles bool `config:"expose_onenote_files"`
Enc encoder.MultiEncoder `config:"encoding"` ServerSideAcrossConfigs bool `config:"server_side_across_configs"`
Enc encoder.MultiEncoder `config:"encoding"`
} }
// Fs represents a remote one drive // Fs represents a remote one drive
@ -577,6 +588,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
CaseInsensitive: true, CaseInsensitive: true,
ReadMimeType: true, ReadMimeType: true,
CanHaveEmptyDirectories: true, CanHaveEmptyDirectories: true,
ServerSideAcrossConfigs: opt.ServerSideAcrossConfigs,
}).Fill(f) }).Fill(f)
f.srv.SetErrorHandler(errorHandler) f.srv.SetErrorHandler(errorHandler)
@ -989,10 +1001,13 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
return nil, err return nil, err
} }
srcPath := srcObj.rootPath() // Check we aren't overwriting a file on the same remote
dstPath := f.rootPath(remote) if srcObj.fs == f {
if strings.ToLower(srcPath) == strings.ToLower(dstPath) { srcPath := srcObj.rootPath()
return nil, errors.Errorf("can't copy %q -> %q as are same name when lowercase", srcPath, dstPath) dstPath := f.rootPath(remote)
if strings.ToLower(srcPath) == strings.ToLower(dstPath) {
return nil, errors.Errorf("can't copy %q -> %q as are same name when lowercase", srcPath, dstPath)
}
} }
// Create temporary object // Create temporary object