From 50e36fb4822c2b23442333f70c6de894bef6fea4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 2 Jul 2020 09:38:37 +0100 Subject: [PATCH] onedrive: Fix reverting to Copy when Move would have worked For some objects the onedrive backend has been doing a server side copy and a delete when a server side move would have worked OK. This was caused by not detecting the home drive correctly (when it was an empty string) and assuming that these transfers were cross drive. This is fixed by comparing canonicalizing drive IDs before comparing them. --- backend/onedrive/onedrive.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index 7a822020a..a41766bfe 100755 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -1107,9 +1107,10 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, id, dstDriveID, _ := parseNormalizedID(directoryID) _, srcObjDriveID, _ := parseNormalizedID(srcObj.id) - if dstDriveID != srcObjDriveID { + if f.canonicalDriveID(dstDriveID) != srcObj.fs.canonicalDriveID(srcObjDriveID) { // https://docs.microsoft.com/en-us/graph/api/driveitem-move?view=graph-rest-1.0 // "Items cannot be moved between Drives using this request." + fs.Debugf(f, "Can't move files between drives (%q != %q)", dstDriveID, srcObjDriveID) return nil, fs.ErrorCantMove } @@ -1168,9 +1169,10 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string parsedDstDirID, dstDriveID, _ := parseNormalizedID(dstDirectoryID) _, srcDriveID, _ := parseNormalizedID(srcID) - if dstDriveID != srcDriveID { + if f.canonicalDriveID(dstDriveID) != srcFs.canonicalDriveID(srcDriveID) { // https://docs.microsoft.com/en-us/graph/api/driveitem-move?view=graph-rest-1.0 // "Items cannot be moved between Drives using this request." + fs.Debugf(f, "Can't move directories between drives (%q != %q)", dstDriveID, srcDriveID) return fs.ErrorCantDirMove } @@ -1787,6 +1789,17 @@ func parseNormalizedID(ID string) (string, string, string) { return ID, "", "" } +// Returns the canonical form of the driveID +func (f *Fs) canonicalDriveID(driveID string) (canonicalDriveID string) { + if driveID == "" { + canonicalDriveID = f.opt.DriveID + } else { + canonicalDriveID = driveID + } + canonicalDriveID = strings.ToLower(canonicalDriveID) + return canonicalDriveID +} + // getRelativePathInsideBase checks if `target` is inside `base`. If so, it // returns a relative path for `target` based on `base` and a boolean `true`. // Otherwise returns "", false.