From 7f854acb0569644f6bab69e550ab6d8e3d281763 Mon Sep 17 00:00:00 2001 From: nielash Date: Wed, 15 Nov 2023 15:12:45 -0500 Subject: [PATCH] local: fix cleanRootPath on Windows after go1.21.4 stdlib update Similar to https://github.com/rclone/rclone/commit/acf1e2df84a350b7a86d7672d749dfb1ba090a44, go1.21.4 appears to have broken sync.MoveDir on Windows because filepath.VolumeName() returns `\\?` instead of `\\?\C:` in cleanRootPath. It looks like the Go team is aware of the issue and planning a fix, so this may only be needed temporarily. --- backend/local/local.go | 4 ++++ fs/sync/sync_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/backend/local/local.go b/backend/local/local.go index c444267f1..832390d5a 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -1447,6 +1447,10 @@ func cleanRootPath(s string, noUNC bool, enc encoder.MultiEncoder) string { if runtime.GOOS == "windows" { s = filepath.ToSlash(s) vol := filepath.VolumeName(s) + if vol == `\\?` && len(s) >= 6 { + // `\\?\C:` + vol = s[:6] + } s = vol + enc.FromStandardPath(s[len(vol):]) s = filepath.FromSlash(s) if !noUNC { diff --git a/fs/sync/sync_test.go b/fs/sync/sync_test.go index 34085ee6e..7911be1d0 100644 --- a/fs/sync/sync_test.go +++ b/fs/sync/sync_test.go @@ -1351,6 +1351,22 @@ func testServerSideMove(ctx context.Context, t *testing.T, r *fstest.Run, withFi } } +// Test MoveDir on Local +func TestServerSideMoveLocal(t *testing.T) { + ctx := context.Background() + r := fstest.NewRun(t) + f1 := r.WriteFile("dir1/file1.txt", "hello", t1) + f2 := r.WriteFile("dir2/file2.txt", "hello again", t2) + r.CheckLocalItems(t, f1, f2) + + dir1, err := fs.NewFs(ctx, r.Flocal.Root()+"/dir1") + require.NoError(t, err) + dir2, err := fs.NewFs(ctx, r.Flocal.Root()+"/dir2") + require.NoError(t, err) + err = MoveDir(ctx, dir2, dir1, false, false) + require.NoError(t, err) +} + // Test move func TestMoveWithDeleteEmptySrcDirs(t *testing.T) { ctx := context.Background()