lib/model: Fix child-check when deleting dirs in pull (#7236)

This commit is contained in:
Simon Frei
2021-01-02 21:40:37 +01:00
committed by GitHub
parent 0f8290485e
commit c48eb4241a
2 changed files with 122 additions and 70 deletions
+27
View File
@@ -11,6 +11,7 @@ import (
"context"
"crypto/rand"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
@@ -1350,6 +1351,32 @@ func TestPullDeleteCaseConflict(t *testing.T) {
}
}
func TestPullDeleteIgnoreChildDir(t *testing.T) {
m, f := setupSendReceiveFolder(t)
defer cleanupSRFolder(f, m)
parent := "parent"
del := "ignored"
child := "keep"
matcher := ignore.New(f.mtimefs)
must(t, matcher.Parse(bytes.NewBufferString(fmt.Sprintf(`
!%v
(?d)%v
`, child, del)), ""))
f.ignores = matcher
must(t, f.mtimefs.Mkdir(parent, 0777))
must(t, f.mtimefs.Mkdir(filepath.Join(parent, del), 0777))
must(t, f.mtimefs.Mkdir(filepath.Join(parent, del, child), 0777))
scanChan := make(chan string, 2)
err := f.deleteDirOnDisk(parent, f.fset.Snapshot(), scanChan)
if err == nil {
t.Error("no error")
}
}
func cleanupSharedPullerState(s *sharedPullerState) {
s.mut.Lock()
defer s.mut.Unlock()