浏览代码

lib/ignore: Consistent behaviour for nil *Matcher

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4310
Simon Frei 8 年之前
父节点
当前提交
9dbc509996
共有 2 个文件被更改,包括 4 次插入5 次删除
  1. 1 5
      lib/ignore/ignore.go
  2. 3 0
      lib/scanner/walk.go

+ 1 - 5
lib/ignore/ignore.go

@@ -173,7 +173,7 @@ func (m *Matcher) parseLocked(r io.Reader, file string) error {
 }
 }
 
 
 func (m *Matcher) Match(file string) (result Result) {
 func (m *Matcher) Match(file string) (result Result) {
-	if m == nil || file == "." {
+	if file == "." {
 		return resultNotMatched
 		return resultNotMatched
 	}
 	}
 
 
@@ -228,10 +228,6 @@ func (m *Matcher) Lines() []string {
 
 
 // Patterns return a list of the loaded patterns, as they've been parsed
 // Patterns return a list of the loaded patterns, as they've been parsed
 func (m *Matcher) Patterns() []string {
 func (m *Matcher) Patterns() []string {
-	if m == nil {
-		return nil
-	}
-
 	m.mut.Lock()
 	m.mut.Lock()
 	defer m.mut.Unlock()
 	defer m.mut.Unlock()
 
 

+ 3 - 0
lib/scanner/walk.go

@@ -85,6 +85,9 @@ func Walk(ctx context.Context, cfg Config) (chan protocol.FileInfo, error) {
 	if w.Filesystem == nil {
 	if w.Filesystem == nil {
 		panic("no filesystem specified")
 		panic("no filesystem specified")
 	}
 	}
+	if w.Matcher == nil {
+		w.Matcher = ignore.New(w.Filesystem)
+	}
 
 
 	return w.walk(ctx)
 	return w.walk(ctx)
 }
 }