From a6779f3d79e0dfb71d08149f0ba35ba5568daab6 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Fri, 13 Nov 2026 17:23:32 +0530 Subject: [PATCH] operations: fix --name-transform applied twice on update - fixes #10332 When copy, sync or move found an existing destination file, Copy and move replaced the transformed source name with a transform of the destination's name. That name is already transformed (it is how the file was matched), so updates went to a doubly transformed name, e.g. prefix-prefix-file.txt instead of prefix-file.txt. Keep the transformed source name when --name-transform is in use and only fall back to the destination's name when it isn't, which keeps the existing case of a file on case-insensitive remotes as before. TransformFile and convmv are unaffected as their dst is the source file itself. --- fs/operations/copy.go | 4 ++-- fs/operations/operations.go | 4 +++- fs/sync/sync_transform_test.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/fs/operations/copy.go b/fs/operations/copy.go index 8ff62d572..eef258f00 100644 --- a/fs/operations/copy.go +++ b/fs/operations/copy.go @@ -417,8 +417,8 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj doUpdate: dst != nil, } c.hashType, c.hashOption = CommonHash(ctx, f, src.Fs()) - if c.dst != nil { - c.remote = transform.Path(ctx, c.dst.Remote(), false) + if c.dst != nil && !transform.Transforming(ctx) { + c.remote = c.dst.Remote() } // Are we using partials? // diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 773fa68be..e1874a1af 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -471,7 +471,9 @@ func move(ctx context.Context, fdst fs.Fs, dst fs.Object, remote string, src fs. if doMove := fdst.Features().Move; doMove != nil && (SameConfig(src.Fs(), fdst) || (SameRemoteType(src.Fs(), fdst) && (fdst.Features().ServerSideAcrossConfigs || ci.ServerSideAcrossConfigs))) { // Delete destination if it exists and is not the same file as src (could be same file while seemingly different if the remote is case insensitive) if dst != nil { - remote = transform.Path(ctx, dst.Remote(), false) + if !transform.Transforming(ctx) { + remote = dst.Remote() + } if !SameObject(src, dst) { err = DeleteFile(ctx, dst) if err != nil { diff --git a/fs/sync/sync_transform_test.go b/fs/sync/sync_transform_test.go index c316f434e..4270ac278 100644 --- a/fs/sync/sync_transform_test.go +++ b/fs/sync/sync_transform_test.go @@ -369,6 +369,37 @@ func TestRunTwice(t *testing.T) { r.CheckRemoteItems(t, fstest.NewItem("tictactoe/tictactoe/toe.txt", "hello world", t1)) } +func TestTransformUpdate(t *testing.T) { + for _, tc := range []struct { + name string + run func(ctx context.Context, fdst, fsrc fs.Fs) error + local bool // whether the source file is still there afterwards + }{ + {"Copy", func(ctx context.Context, fdst, fsrc fs.Fs) error { return CopyDir(ctx, fdst, fsrc, true) }, true}, + {"Sync", func(ctx context.Context, fdst, fsrc fs.Fs) error { return Sync(ctx, fdst, fsrc, true) }, true}, + {"Move", func(ctx context.Context, fdst, fsrc fs.Fs) error { return MoveDir(ctx, fdst, fsrc, false, true) }, false}, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := context.Background() + r := newTransformRun(t) + err := transform.SetOptions(ctx, "all,prefix=tac") + require.NoError(t, err) + file1 := r.WriteFile("toe/toe.txt", "new content", t2) + r.WriteObject(ctx, "tactoe/tactoe.txt", "old", t1) + + err = tc.run(ctx, r.Fremote, r.Flocal) + require.NoError(t, err) + + if tc.local { + r.CheckLocalItems(t, file1) + } else { + r.CheckLocalItems(t) + } + r.CheckRemoteItems(t, fstest.NewItem("tactoe/tactoe.txt", "new content", t2)) + }) + } +} + func TestSyntax(t *testing.T) { ctx := context.Background() err := transform.SetOptions(ctx, "prefix")