lib/model: GetIgnores: Don't return error for no .stignore file

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4311
This commit is contained in:
Simon Frei 2017-08-22 06:48:25 +00:00 committed by Jakob Borg
parent 0a96a1150b
commit 0ca0e3e9bd
2 changed files with 19 additions and 11 deletions

View File

@ -1250,25 +1250,28 @@ func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
defer m.fmut.RUnlock() defer m.fmut.RUnlock()
cfg, ok := m.folderCfgs[folder] cfg, ok := m.folderCfgs[folder]
if ok { if !ok {
if !cfg.HasMarker() { cfg, ok = m.cfg.Folders()[folder]
return nil, nil, fmt.Errorf("Folder %s stopped", folder) if !ok {
return nil, nil, fmt.Errorf("Folder %s does not exist", folder)
} }
}
ignores := m.folderIgnores[folder] if err := m.checkFolderPath(cfg); err != nil {
return nil, nil, err
}
ignores, ok := m.folderIgnores[folder]
if ok {
return ignores.Lines(), ignores.Patterns(), nil return ignores.Lines(), ignores.Patterns(), nil
} }
if cfg, ok := m.cfg.Folders()[folder]; ok { ignores = ignore.New(fs.NewFilesystem(cfg.FilesystemType, cfg.Path))
matcher := ignore.New(cfg.Filesystem()) if err := ignores.Load(".stignore"); err != nil && !fs.IsNotExist(err) {
if err := matcher.Load(".stignore"); err != nil { return nil, nil, err
return nil, nil, err
}
return matcher.Lines(), matcher.Patterns(), nil
} }
return nil, nil, fmt.Errorf("Folder %s does not exist", folder) return ignores.Lines(), ignores.Patterns(), nil
} }
func (m *Model) SetIgnores(folder string, content []string) error { func (m *Model) SetIgnores(folder string, content []string) error {

View File

@ -1083,6 +1083,11 @@ func TestIgnores(t *testing.T) {
// added to the model and thus there is no initial scan happening. // added to the model and thus there is no initial scan happening.
changeIgnores(t, m, expected) changeIgnores(t, m, expected)
// Make sure no .stignore file is considered valid
os.Rename("testdata/.stignore", "testdata/.stignore.bak")
changeIgnores(t, m, []string{})
os.Rename("testdata/.stignore.bak", "testdata/.stignore")
} }
func TestROScanRecovery(t *testing.T) { func TestROScanRecovery(t *testing.T) {