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.
This commit is contained in:
1 parent
66196f7f22
commit
a6779f3d79
3 files changed
+36
-3
No files matched your search
@@ -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?
|
||||
//
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user