From 7c1f2d7c841b56136987a44ca58f5d0505ccb00d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 9 Jun 2022 12:45:24 +0100 Subject: [PATCH] dirtree: fix tests with -fast-list In commit da404dc0f28e919c sync,copy: Fix --fast-list --create-empty-src-dirs and --exclude The fix caused DirTree.AddDir to be called with the root directory. This in turn caused a spurious directory entry in the DirTree which caused tests with the -fast-list flag to fail with directory not found errors. --- fs/dirtree/dirtree.go | 5 ++++- fs/dirtree/dirtree_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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()) }