From 885e3f19bd27ed592ccee0a07013f63dab1bbe7b Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sat, 20 Jan 2018 07:52:57 +0000 Subject: [PATCH] lib/ignores: Update lines even if patterns didn't change (fixes #4689) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4690 --- lib/ignore/ignore.go | 3 ++- lib/ignore/ignore_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index 224716574..e1a833ed2 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -156,6 +156,8 @@ func (m *Matcher) parseLocked(r io.Reader, file string) error { // Error is saved and returned at the end. We process the patterns // (possibly blank) anyway. + m.lines = lines + newHash := hashPatterns(patterns) if newHash == m.curHash { // We've already loaded exactly these patterns. @@ -163,7 +165,6 @@ func (m *Matcher) parseLocked(r io.Reader, file string) error { } m.curHash = newHash - m.lines = lines m.patterns = patterns if m.withCache { m.matches = newCache(patterns) diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index 108687c78..f15ffd9ba 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -956,3 +956,28 @@ func TestIssue4680(t *testing.T) { } } } + +func TestIssue4689(t *testing.T) { + stignore := `// orig` + + pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, "."), WithCache(true)) + err := pats.Parse(bytes.NewBufferString(stignore), ".stignore") + if err != nil { + t.Fatal(err) + } + + if lines := pats.Lines(); len(lines) != 1 || lines[0] != "// orig" { + t.Fatalf("wrong lines parsing original comment:\n%q", lines) + } + + stignore = `// new` + + err = pats.Parse(bytes.NewBufferString(stignore), ".stignore") + if err != nil { + t.Fatal(err) + } + + if lines := pats.Lines(); len(lines) != 1 || lines[0] != "// new" { + t.Fatalf("wrong lines parsing changed comment:\n%v", lines) + } +}