From 77a161a0870cd89ea5942632f684edac8bdf874c Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Mon, 27 Apr 2015 20:49:10 +0100 Subject: [PATCH] Matcher checks nil receiver --- internal/ignore/ignore.go | 8 ++++++++ internal/model/model.go | 9 +++------ internal/scanner/walk.go | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/ignore/ignore.go b/internal/ignore/ignore.go index ee50048f9..ca216ea31 100644 --- a/internal/ignore/ignore.go +++ b/internal/ignore/ignore.go @@ -95,6 +95,10 @@ func (m *Matcher) Parse(r io.Reader, file string) error { } func (m *Matcher) Match(file string) (result bool) { + if m == nil { + return false + } + m.mut.Lock() defer m.mut.Unlock() @@ -128,6 +132,10 @@ func (m *Matcher) Match(file string) (result bool) { // Patterns return a list of the loaded regexp patterns, as strings func (m *Matcher) Patterns() []string { + if m == nil { + return nil + } + m.mut.Lock() defer m.mut.Unlock() diff --git a/internal/model/model.go b/internal/model/model.go index 853c6f586..061625a80 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -858,10 +858,7 @@ func (m *Model) GetIgnores(folder string) ([]string, []string, error) { } m.fmut.RLock() - var patterns []string - if matcher := m.folderIgnores[folder]; matcher != nil { - patterns = matcher.Patterns() - } + patterns := m.folderIgnores[folder].Patterns() m.fmut.RUnlock() return lines, patterns, nil @@ -1010,7 +1007,7 @@ func sendIndexTo(initial bool, minLocalVer int64, conn protocol.Connection, fold maxLocalVer = f.LocalVersion } - if (ignores != nil && ignores.Match(f.Name)) || symlinkInvalid(f.IsSymlink()) { + if ignores.Match(f.Name) || symlinkInvalid(f.IsSymlink()) { if debug { l.Debugln("not sending update for ignored/unsupported symlink", f) } @@ -1281,7 +1278,7 @@ nextSub: batch = batch[:0] } - if (ignores != nil && ignores.Match(f.Name)) || symlinkInvalid(f.IsSymlink()) { + if ignores.Match(f.Name) || symlinkInvalid(f.IsSymlink()) { // File has been ignored or an unsupported symlink. Set invalid bit. if debug { l.Debugln("setting invalid bit on ignored", f) diff --git a/internal/scanner/walk.go b/internal/scanner/walk.go index 5bfae552d..5fcfeb0ed 100644 --- a/internal/scanner/walk.go +++ b/internal/scanner/walk.go @@ -158,7 +158,7 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun } if sn := filepath.Base(rn); sn == ".stignore" || sn == ".stfolder" || - strings.HasPrefix(rn, ".stversions") || (w.Matcher != nil && w.Matcher.Match(rn)) { + strings.HasPrefix(rn, ".stversions") || w.Matcher.Match(rn) { // An ignored file if debug { l.Debugln("ignored:", rn)