Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fstests: List missing dir must return ErrorDirNotFound for non bucket based remotes

Nick Craig-Wood9fbc40c5b987
diff --git a/cmd/ls/lshelp/lshelp.go b/cmd/ls/lshelp/lshelp.go
index 8b713636b..cb4c656eb 100644
--- a/cmd/ls/lshelp/lshelp.go
+++ b/cmd/ls/lshelp/lshelp.go
@@ -19,4 +19,8 @@ There are several related list commands
Note that ` + "`ls`,`lsl`,`lsd`" + ` all recurse by default - use "--max-depth 1" to stop the recursion.
The other list commands ` + "`lsf`,`lsjson`" + ` do not recurse by default - use "-R" to make them recurse.
+
+Listing a non existent directory will produce an error except for
+remotes which can't have empty directories (eg s3, swift, gcs, etc -
+the bucket based remotes).
`
diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go
index 304bba178..961f861dd 100644
--- a/fstest/fstests/fstests.go
+++ b/fstest/fstests/fstests.go
@@ -335,6 +335,27 @@ func Run(t *testing.T, opt *Opt) {
TestFsListDirEmpty(t)
})
+ // TestFsListDirNotFound tests listing the directories from an empty directory
+ TestFsListDirNotFound := func(t *testing.T) {
+ skipIfNotOk(t)
+ objs, dirs, err := walk.GetAll(remote, "does not exist", true, 1)
+ if !remote.Features().CanHaveEmptyDirectories {
+ if err != fs.ErrorDirNotFound {
+ assert.NoError(t, err)
+ assert.Equal(t, 0, len(objs)+len(dirs))
+ }
+ } else {
+ assert.Equal(t, fs.ErrorDirNotFound, err)
+ }
+ }
+ t.Run("TestFsListDirNotFound", TestFsListDirNotFound)
+
+ // TestFsListRDirNotFound tests listing the directories from an empty directory using ListR
+ t.Run("TestFsListRDirNotFound", func(t *testing.T) {
+ defer skipIfNotListR(t)()
+ TestFsListDirNotFound(t)
+ })
+
// TestFsNewObjectNotFound tests not finding a object
t.Run("TestFsNewObjectNotFound", func(t *testing.T) {
skipIfNotOk(t)
@@ -666,10 +687,9 @@ func Run(t *testing.T, opt *Opt) {
require.NoError(t, err)
// check remotes
- // FIXME: Prints errors.
// remote should not exist here
_, err = remote.List("")
- require.Equal(t, fs.ErrorDirNotFound, errors.Cause(err))
+ assert.Equal(t, fs.ErrorDirNotFound, errors.Cause(err))
//fstest.CheckListingWithPrecision(t, remote, []fstest.Item{}, []string{}, remote.Precision())
file1Copy := file1
file1Copy.Path = path.Join(newName, file1.Path)