summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Borg <jakob@nym.se>2015-09-29 18:01:19 +0200
committerJakob Borg <jakob@nym.se>2015-10-02 08:00:16 +0200
commit5fab25effd3b79106d74bfc91e5eac6d81ab64c0 (patch)
tree2cc09b52f1cde13808103ef92a60eb212130def4
parentd746b043c8f0b92218c430e97cdcb14d06df6f25 (diff)
Correctly report errors encountered parsing ignores (fixes #2309, fixes #2296)
An error on opening .stignore will satisfy os.IsNotExist() and not be reported. Other errors will be reported and stop the folder, including is-not-exist errors from #include as these are passed through fmt.Errorf. Also fixes minor issue where we would not print cause of folder stopping to the log. Also fixes minor issue with capitalization of errors.
-rw-r--r--lib/ignore/ignore.go15
-rw-r--r--lib/model/model.go13
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go
index 8c8cabf2c0..abddc23441 100644
--- a/lib/ignore/ignore.go
+++ b/lib/ignore/ignore.go
@@ -216,27 +216,28 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
// Pattern is rooted in the current dir only
exp, err := fnmatch.Convert(line[1:], flags)
if err != nil {
- return fmt.Errorf("Invalid pattern %q in ignore file", line)
+ return fmt.Errorf("invalid pattern %q in ignore file", line)
}
patterns = append(patterns, Pattern{exp, include})
} else if strings.HasPrefix(line, "**/") {
// Add the pattern as is, and without **/ so it matches in current dir
exp, err := fnmatch.Convert(line, flags)
if err != nil {
- return fmt.Errorf("Invalid pattern %q in ignore file", line)
+ return fmt.Errorf("invalid pattern %q in ignore file", line)
}
patterns = append(patterns, Pattern{exp, include})
exp, err = fnmatch.Convert(line[3:], flags)
if err != nil {
- return fmt.Errorf("Invalid pattern %q in ignore file", line)
+ return fmt.Errorf("invalid pattern %q in ignore file", line)
}
patterns = append(patterns, Pattern{exp, include})
} else if strings.HasPrefix(line, "#include ") {
- includeFile := filepath.Join(filepath.Dir(currentFile), line[len("#include "):])
+ includeRel := line[len("#include "):]
+ includeFile := filepath.Join(filepath.Dir(currentFile), includeRel)
includes, err := loadIgnoreFile(includeFile, seen)
if err != nil {
- return err
+ return fmt.Errorf("include of %q: %v", includeRel, err)
}
patterns = append(patterns, includes...)
} else {
@@ -244,13 +245,13 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
// current directory and subdirs.
exp, err := fnmatch.Convert(line, flags)
if err != nil {
- return fmt.Errorf("Invalid pattern %q in ignore file", line)
+ return fmt.Errorf("invalid pattern %q in ignore file", line)
}
patterns = append(patterns, Pattern{exp, include})
exp, err = fnmatch.Convert("**/"+line, flags)
if err != nil {
- return fmt.Errorf("Invalid pattern %q in ignore file", line)
+ return fmt.Errorf("invalid pattern %q in ignore file", line)
}
patterns = append(patterns, Pattern{exp, include})
}
diff --git a/lib/model/model.go b/lib/model/model.go
index 4e0373fe5c..991bf5851f 100644
--- a/lib/model/model.go
+++ b/lib/model/model.go
@@ -1144,7 +1144,9 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) {
}
ignores := ignore.New(m.cacheIgnoredFiles)
- _ = ignores.Load(filepath.Join(cfg.Path(), ".stignore")) // Ignore error, there might not be an .stignore
+ if err := ignores.Load(filepath.Join(cfg.Path(), ".stignore")); err != nil && !os.IsNotExist(err) {
+ l.Warnln("Loading ignores:", err)
+ }
m.folderIgnores[cfg.ID] = ignores
m.fmut.Unlock()
@@ -1231,10 +1233,17 @@ func (m *Model) internalScanFolderSubs(folder string, subs []string) error {
}
if err := m.CheckFolderHealth(folder); err != nil {
+ runner.setError(err)
+ l.Infof("Stopping folder %s due to error: %s", folder, err)
return err
}
- _ = ignores.Load(filepath.Join(folderCfg.Path(), ".stignore")) // Ignore error, there might not be an .stignore
+ if err := ignores.Load(filepath.Join(folderCfg.Path(), ".stignore")); err != nil && !os.IsNotExist(err) {
+ err = fmt.Errorf("loading ignores: %v", err)
+ runner.setError(err)
+ l.Infof("Stopping folder %s due to error: %s", folder, err)
+ return err
+ }
// Required to make sure that we start indexing at a directory we're already
// aware off.