Merge pull request #2332 from calmh/brokenignore
Correctly report errors encountered parsing ignores (fixes #2309)
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -217,28 +216,28 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
|||||||
// Pattern is rooted in the current dir only
|
// Pattern is rooted in the current dir only
|
||||||
exp, err := fnmatch.Convert(line[1:], flags)
|
exp, err := fnmatch.Convert(line[1:], flags)
|
||||||
if err != nil {
|
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})
|
patterns = append(patterns, Pattern{exp, include})
|
||||||
} else if strings.HasPrefix(line, "**/") {
|
} else if strings.HasPrefix(line, "**/") {
|
||||||
// Add the pattern as is, and without **/ so it matches in current dir
|
// Add the pattern as is, and without **/ so it matches in current dir
|
||||||
exp, err := fnmatch.Convert(line, flags)
|
exp, err := fnmatch.Convert(line, flags)
|
||||||
if err != nil {
|
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})
|
patterns = append(patterns, Pattern{exp, include})
|
||||||
|
|
||||||
exp, err = fnmatch.Convert(line[3:], flags)
|
exp, err = fnmatch.Convert(line[3:], flags)
|
||||||
if err != nil {
|
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})
|
patterns = append(patterns, Pattern{exp, include})
|
||||||
} else if strings.HasPrefix(line, "#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)
|
includes, err := loadIgnoreFile(includeFile, seen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
return fmt.Errorf("include of %q: %v", includeRel, err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
patterns = append(patterns, includes...)
|
patterns = append(patterns, includes...)
|
||||||
} else {
|
} else {
|
||||||
@@ -246,13 +245,13 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
|||||||
// current directory and subdirs.
|
// current directory and subdirs.
|
||||||
exp, err := fnmatch.Convert(line, flags)
|
exp, err := fnmatch.Convert(line, flags)
|
||||||
if err != nil {
|
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})
|
patterns = append(patterns, Pattern{exp, include})
|
||||||
|
|
||||||
exp, err = fnmatch.Convert("**/"+line, flags)
|
exp, err = fnmatch.Convert("**/"+line, flags)
|
||||||
if err != nil {
|
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})
|
patterns = append(patterns, Pattern{exp, include})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1183,7 +1183,9 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ignores := ignore.New(m.cacheIgnoredFiles)
|
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.folderIgnores[cfg.ID] = ignores
|
||||||
|
|
||||||
m.fmut.Unlock()
|
m.fmut.Unlock()
|
||||||
@@ -1270,10 +1272,17 @@ func (m *Model) internalScanFolderSubs(folder string, subs []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := m.CheckFolderHealth(folder); err != nil {
|
if err := m.CheckFolderHealth(folder); err != nil {
|
||||||
|
runner.setError(err)
|
||||||
|
l.Infof("Stopping folder %s due to error: %s", folder, err)
|
||||||
return 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
|
// Required to make sure that we start indexing at a directory we're already
|
||||||
// aware off.
|
// aware off.
|
||||||
|
|||||||
Reference in New Issue
Block a user