lib/model: Handle (?d) deletes of directories (fixes #3164)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3170
This commit is contained in:
Audrius Butkevicius
2016-05-23 23:32:08 +00:00
committed by Jakob Borg
parent b78bfc0a43
commit 915e1ac7de
4 changed files with 117 additions and 4 deletions

View File

@@ -246,8 +246,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
addPattern := func(line string) error {
pattern := Pattern{
pattern: line,
result: defaultResult,
result: defaultResult,
}
// Allow prefixes to be specified in any order, but only once.
@@ -275,6 +274,8 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
line = strings.ToLower(line)
}
pattern.pattern = line
var err error
if strings.HasPrefix(line, "/") {
// Pattern is rooted in the current dir only

View File

@@ -665,3 +665,41 @@ func TestCommas(t *testing.T) {
}
}
}
func TestIssue3164(t *testing.T) {
stignore := `
(?d)(?i)*.part
(?d)(?i)/foo
(?d)(?i)**/bar
`
pats := New(true)
err := pats.Parse(bytes.NewBufferString(stignore), ".stignore")
if err != nil {
t.Fatal(err)
}
expanded := pats.Patterns()
t.Log(expanded)
expected := []string{
"(?d)(?i)*.part",
"(?d)(?i)**/*.part",
"(?d)(?i)*.part/**",
"(?d)(?i)**/*.part/**",
"(?d)(?i)/foo",
"(?d)(?i)/foo/**",
"(?d)(?i)**/bar",
"(?d)(?i)bar",
"(?d)(?i)**/bar/**",
"(?d)(?i)bar/**",
}
if len(expanded) != len(expected) {
t.Errorf("Unmatched count: %d != %d", len(expanded), len(expected))
}
for i := range expanded {
if expanded[i] != expected[i] {
t.Errorf("Pattern %d does not match: %s != %s", i, expanded[i], expected[i])
}
}
}