"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
Add test for cache renaming functionality
Brett Dutro53d55ae7608c
diff --git a/vfs/cache.go b/vfs/cache.goindex c84d2c76b..41ace3005 100644--- a/vfs/cache.go+++ b/vfs/cache.go@@ -6,7 +6,6 @@ import ("context""fmt""os"- "path""path/filepath""runtime""sort"@@ -120,7 +119,7 @@ func newCache(ctx context.Context, f fs.Fs, opt *Options) (*cache, error) {// findParent returns the parent directory of name, or "" for the rootfunc findParent(name string) string {- parent := path.Dir(name)+ parent := filepath.Dir(name)if parent == "." || parent == "/" {parent = ""}@@ -130,7 +129,7 @@ func findParent(name string) string {// clean returns the cleaned version of name for use in the index mapfunc clean(name string) string {name = strings.Trim(name, "/")- name = path.Clean(name)+ name = filepath.Clean(name)if name == "." || name == "/" {name = ""}@@ -146,7 +145,7 @@ func (c *cache) toOSPath(name string) string {// path for the filefunc (c *cache) mkdir(name string) (string, error) {parent := findParent(name)- leaf := path.Base(name)+ leaf := filepath.Base(name)parentPath := c.toOSPath(parent)err := os.MkdirAll(parentPath, 0700)if err != nil {diff --git a/vfs/cache_test.go b/vfs/cache_test.goindex 4f29d46dc..d6affea3c 100644--- a/vfs/cache_test.go+++ b/vfs/cache_test.go@@ -51,7 +51,7 @@ func itemAsString(c *cache) []string {defer c.itemMu.Unlock()var out []stringfor name, item := range c.item {- out = append(out, fmt.Sprintf("name=%q isFile=%v opens=%d size=%d", name, item.isFile, item.opens, item.size))+ out = append(out, fmt.Sprintf("name=%q isFile=%v opens=%d size=%d", filepath.ToSlash(name), item.isFile, item.opens, item.size))}sort.Strings(out)return out@@ -386,11 +386,11 @@ func TestCachePurgeOld(t *testing.T) {var removed []stringremovedDir := trueremoveFile := func(name string) {- removed = append(removed, name)+ removed = append(removed, filepath.ToSlash(name))}removeDir := func(name string) bool {if removedDir {- removed = append(removed, name+"/")+ removed = append(removed, filepath.ToSlash(name)+"/")}return removedDir}@@ -483,7 +483,7 @@ func TestCachePurgeOverQuota(t *testing.T) {// Test funcsvar removed []stringremove := func(name string) {- removed = append(removed, name)+ removed = append(removed, filepath.ToSlash(name))c.remove(name)}diff --git a/vfs/read_write_test.go b/vfs/read_write_test.goindex 257d120ce..3d1df648a 100644--- a/vfs/read_write_test.go+++ b/vfs/read_write_test.go@@ -609,3 +609,30 @@ func TestRWFileModTimeWithOpenWriters(t *testing.T) {assert.Equal(t, info.ModTime().Unix(), mtime.Unix())}}++func TestCacheRename(t *testing.T) {+ r := fstest.NewRun(t)+ defer r.Finalise()++ opt := DefaultOpt+ opt.CacheMode = CacheModeFull+ vfs := New(r.Fremote, &opt)++ h, err := vfs.OpenFile("rename_me", os.O_WRONLY|os.O_CREATE, 0777)+ require.NoError(t, err)+ fh, ok := h.(*RWFileHandle)+ require.True(t, ok)++ err = fh.Sync()+ require.NoError(t, err)+ err = fh.Close()+ require.NoError(t, err)++ assert.True(t, vfs.cache.exists("rename_me"))++ err = vfs.Rename("rename_me", "i_was_renamed")+ require.NoError(t, err)++ assert.False(t, vfs.cache.exists("rename_me"))+ assert.True(t, vfs.cache.exists("i_was_renamed"))+}