"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
tests for --exclude-if-present
Iakov Davydov7d3abdc46362
diff --git a/fs/operations_test.go b/fs/operations_test.goindex 72124c678..58782f578 100644--- a/fs/operations_test.go+++ b/fs/operations_test.go@@ -743,6 +743,8 @@ func TestListDirSorted(t *testing.T) {r.WriteObject("zend.txt", "hello", t1),r.WriteObject("sub dir/hello world", "hello world", t1),r.WriteObject("sub dir/hello world2", "hello world", t1),+ r.WriteObject("sub dir/ignore dir/.ignore", "", t1),+ r.WriteObject("sub dir/ignore dir/should be ignored", "to ignore", t1),r.WriteObject("sub dir/sub sub dir/hello world3", "hello world", t1),}fstest.CheckItems(t, r.Fremote, files...)@@ -779,15 +781,42 @@ func TestListDirSorted(t *testing.T) {items, err = fs.ListDirSorted(r.Fremote, true, "sub dir")require.NoError(t, err)- require.Len(t, items, 3)+ require.Len(t, items, 4)assert.Equal(t, "sub dir/hello world", str(0))assert.Equal(t, "sub dir/hello world2", str(1))- assert.Equal(t, "sub dir/sub sub dir/", str(2))+ assert.Equal(t, "sub dir/ignore dir/", str(2))+ assert.Equal(t, "sub dir/sub sub dir/", str(3))++ items, err = fs.ListDirSorted(r.Fremote, false, "sub dir")+ require.NoError(t, err)+ require.Len(t, items, 2)+ assert.Equal(t, "sub dir/ignore dir/", str(0))+ assert.Equal(t, "sub dir/sub sub dir/", str(1))++ // testing ignore file+ fs.Config.Filter.ExcludeFile = ".ignore"items, err = fs.ListDirSorted(r.Fremote, false, "sub dir")require.NoError(t, err)require.Len(t, items, 1)assert.Equal(t, "sub dir/sub sub dir/", str(0))++ items, err = fs.ListDirSorted(r.Fremote, false, "sub dir/ignore dir")+ require.NoError(t, err)+ require.Len(t, items, 0)++ items, err = fs.ListDirSorted(r.Fremote, true, "sub dir/ignore dir")+ require.NoError(t, err)+ require.Len(t, items, 2)+ assert.Equal(t, "sub dir/ignore dir/.ignore", str(0))+ assert.Equal(t, "sub dir/ignore dir/should be ignored", str(1))++ fs.Config.Filter.ExcludeFile = ""+ items, err = fs.ListDirSorted(r.Fremote, false, "sub dir/ignore dir")+ require.NoError(t, err)+ require.Len(t, items, 2)+ assert.Equal(t, "sub dir/ignore dir/.ignore", str(0))+ assert.Equal(t, "sub dir/ignore dir/should be ignored", str(1))}type byteReader struct {diff --git a/fs/walk_test.go b/fs/walk_test.goindex 6f4fb6bfd..362b31901 100644--- a/fs/walk_test.go+++ b/fs/walk_test.go@@ -588,3 +588,76 @@ a/assert.Equal(t, test.want, r.String(), fmt.Sprintf("%+v", test))}}++func TestWalkRDirTreeExclude(t *testing.T) {+ for _, test := range []struct {+ entries DirEntries+ want string+ err error+ root string+ level int+ excludeFile string+ includeAll bool+ }{+ {DirEntries{mockObject("a"), mockObject("ignore")}, "", nil, "", -1, "ignore", false},+ {DirEntries{mockObject("a")}, `/+ a+`, nil, "", -1, "ignore", false},+ {DirEntries{+ mockObject("a"),+ mockObject("b/b"),+ mockObject("b/.ignore"),+ }, `/+ a+`, nil, "", -1, ".ignore", false},+ {DirEntries{+ mockObject("a"),+ mockObject("b/.ignore"),+ mockObject("b/b"),+ }, `/+ a+ b/+b/+ .ignore+ b+`, nil, "", -1, ".ignore", true},+ {DirEntries{+ mockObject("a"),+ mockObject("b/b"),+ mockObject("b/c/d/e"),+ mockObject("b/c/ign"),+ mockObject("b/c/x"),+ }, `/+ a+ b/+b/+ b+`, nil, "", -1, "ign", false},+ {DirEntries{+ mockObject("a"),+ mockObject("b/b"),+ mockObject("b/c/d/e"),+ mockObject("b/c/ign"),+ mockObject("b/c/x"),+ }, `/+ a+ b/+b/+ b+ c/+b/c/+ d/+ ign+ x+b/c/d/+ e+`, nil, "", -1, "ign", true},+ } {+ Config.Filter.ExcludeFile = test.excludeFile+ r, err := walkRDirTree(nil, test.root, test.includeAll, test.level, makeListRCallback(test.entries, test.err))+ assert.Equal(t, test.err, err, fmt.Sprintf("%+v", test))+ assert.Equal(t, test.want, r.String(), fmt.Sprintf("%+v", test))+ }+ // Set to default value, to avoid side effects+ Config.Filter.ExcludeFile = ""+}