"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
vfs: fix renamed items listed twice after a case or Unicode-only match
nielash694dae2ed712
diff --git a/vfs/dir.go b/vfs/dir.goindex 1d9d47609..111c0995b 100644--- a/vfs/dir.go+++ b/vfs/dir.go@@ -1223,6 +1223,8 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {fs.Errorf(oldPath, "Dir.Rename error: %v", err)return err}+ // oldName may only match oldNode with case or unicode normalization+ oldLeaf := oldNode.Name()switch x := oldNode.DirEntry().(type) {case nil:if oldFile, ok := oldNode.(*File); ok {@@ -1274,7 +1276,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {}// Show moved - delete from old dir and add to new- d.delObject(oldName)+ d.delObject(oldLeaf)destDir.addObject(oldNode)if err = d.SetModTime(time.Now()); err != nil {fs.Errorf(d, "Dir.Rename failed to set modtime on parent dir: %v", err)diff --git a/vfs/vfs_case_test.go b/vfs/vfs_case_test.goindex 7e634ad4a..428afb37c 100644--- a/vfs/vfs_case_test.go+++ b/vfs/vfs_case_test.go@@ -195,3 +195,42 @@ func TestUnicodeNormalization(t *testing.T) {assertFileDataVFS(t, vfs, norm.NFD.String(both), "data1")assertFileAbsentVFS(t, vfs, nfd)}++func TestRenameByNormalizedName(t *testing.T) {+ r := fstest.NewRun(t)+ features := r.Fremote.Features()+ if features.DirMove == nil && features.Move == nil && features.Copy == nil {+ t.Skip("can't rename directories")+ }++ var (+ nfc = norm.NFC.String(norm.NFD.String("ěáñ"))+ nfd = norm.NFD.String(nfc)+ )++ ctx := context.Background()+ r.WriteObject(ctx, "FiLeA", "data1", t1)+ r.WriteObject(ctx, nfc+".txt", "data2", t2)++ opt := vfscommon.Opt+ opt.CaseInsensitive = true+ vfs := New(ctx, r.Fremote, &opt)+ defer cleanupVFS(t, vfs)++ root, err := vfs.Root()+ require.NoError(t, err)+ _, err = root.Mkdir("DiRa")+ require.NoError(t, err)+ _, err = root.Mkdir(nfc)+ require.NoError(t, err)++ for _, names := range [][2]string{+ {"FILEA", "file1"},+ {nfd + ".txt", "file2"},+ {"DIRA", "dir1"},+ {nfd, "dir2"},+ } {+ require.NoError(t, root.Rename(names[0], names[1], root))+ }+ checkListing(t, root, []string{"dir1,0,true", "dir2,0,true", "file1,5,false", "file2,5,false"})+}