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

dirtree: fix tests with -fast-list

Nick Craig-Wood7c1f2d7c841b
diff --git a/fs/dirtree/dirtree.go b/fs/dirtree/dirtree.go
index cb78ab9df..2785dcbed 100644
--- a/fs/dirtree/dirtree.go
+++ b/fs/dirtree/dirtree.go
@@ -40,9 +40,12 @@ func (dt DirTree) Add(entry fs.DirEntry) {
// this creates the directory itself if required
// it doesn't create parents
func (dt DirTree) AddDir(entry fs.DirEntry) {
+ dirPath := entry.Remote()
+ if dirPath == "" {
+ return
+ }
dt.Add(entry)
// create the directory itself if it doesn't exist already
- dirPath := entry.Remote()
if _, ok := dt[dirPath]; !ok {
dt[dirPath] = nil
}
diff --git a/fs/dirtree/dirtree_test.go b/fs/dirtree/dirtree_test.go
index b292ade0a..d548d8c6f 100644
--- a/fs/dirtree/dirtree_test.go
+++ b/fs/dirtree/dirtree_test.go
@@ -51,6 +51,14 @@ func TestDirTreeAddDir(t *testing.T) {
dir/subdir/
sausage/
dir/subdir/sausage/
+`, dt.String())
+ d = mockdir.New("")
+ dt.AddDir(d)
+ assert.Equal(t, `/
+ potato/
+dir/subdir/
+ sausage/
+dir/subdir/sausage/
`, dt.String())
}