Skip to content

Commit 359260c

Browse files
nielashncw
authored andcommitted
operations: fix TransformFile when can't server-side copy/move
1 parent 125c8a9 commit 359260c

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

fs/operations/operations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ func move(ctx context.Context, fdst fs.Fs, dst fs.Object, remote string, src fs.
493493
}
494494
}
495495
// Move not found or didn't work so copy dst <- src
496+
if origRemote != remote {
497+
dst = nil
498+
}
496499
newDst, err = Copy(ctx, fdst, dst, origRemote, src)
497500
if err != nil {
498501
fs.Errorf(src, "Not deleting source as copy failed: %v", err)

fs/sync/sync_transform_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,36 @@ func TestTransformFile(t *testing.T) {
437437
r.CheckRemoteListing(t, []fstest.Item{fstest.NewItem("toe/toe/toe.txt", "hello world", t1)}, []string{"tictacempty_dir", "tictactoe", "tictactoe/tictactoe", "toe", "toe/toe"})
438438
}
439439

440+
func TestManualTransformFile(t *testing.T) {
441+
ctx := context.Background()
442+
r := fstest.NewRun(t)
443+
444+
r.Flocal.Features().DisableList([]string{"Copy", "Move"})
445+
r.Fremote.Features().DisableList([]string{"Copy", "Move"})
446+
447+
err := transform.SetOptions(ctx, "all,prefix=tac", "all,prefix=tic")
448+
require.NoError(t, err)
449+
r.WriteFile("toe/toe/toe.txt", "hello world", t1)
450+
_, err = operations.MkdirModTime(ctx, r.Flocal, "empty_dir", t1)
451+
require.NoError(t, err)
452+
453+
r.Mkdir(ctx, r.Fremote)
454+
ctx = predictDstFromLogger(ctx)
455+
err = MoveDir(ctx, r.Fremote, r.Flocal, true, true)
456+
testLoggerVsLsf(ctx, r.Fremote, r.Flocal, operations.GetLoggerOpt(ctx).JSON, t)
457+
require.NoError(t, err)
458+
459+
r.CheckLocalListing(t, []fstest.Item{}, []string{})
460+
r.CheckRemoteListing(t, []fstest.Item{fstest.NewItem("tictactoe/tictactoe/tictactoe.txt", "hello world", t1)}, []string{"tictacempty_dir", "tictactoe", "tictactoe/tictactoe"})
461+
462+
err = transform.SetOptions(ctx, "all,trimprefix=tic", "all,trimprefix=tac")
463+
require.NoError(t, err)
464+
err = operations.TransformFile(ctx, r.Fremote, "tictactoe/tictactoe/tictactoe.txt")
465+
require.NoError(t, err)
466+
r.CheckLocalListing(t, []fstest.Item{}, []string{})
467+
r.CheckRemoteListing(t, []fstest.Item{fstest.NewItem("toe/toe/toe.txt", "hello world", t1)}, []string{"tictacempty_dir", "tictactoe", "tictactoe/tictactoe", "toe", "toe/toe"})
468+
}
469+
440470
func TestBase64(t *testing.T) {
441471
ctx := context.Background()
442472
r := fstest.NewRun(t)

0 commit comments

Comments
 (0)