dirtree: fix tests with -fast-list

In commit

da404dc0f2 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.
This commit is contained in:
Nick Craig-Wood 2022-06-09 12:45:24 +01:00
parent 5db9a2f831
commit 7c1f2d7c84
2 changed files with 12 additions and 1 deletions

View File

@ -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
}

View File

@ -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())
}