diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 1408ee1b0..c51e4487e 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -476,13 +476,15 @@ func restGetIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) { qs := r.URL.Query() w.Header().Set("Content-Type", "application/json; charset=utf-8") - ignores, err := m.GetIgnores(qs.Get("folder")) + ignores, patterns, err := m.GetIgnores(qs.Get("folder")) if err != nil { http.Error(w, err.Error(), 500) return } + json.NewEncoder(w).Encode(map[string][]string{ - "ignore": ignores, + "ignore": ignores, + "patterns": patterns, }) } diff --git a/internal/ignore/ignore.go b/internal/ignore/ignore.go index 39ab7d21e..69357673b 100644 --- a/internal/ignore/ignore.go +++ b/internal/ignore/ignore.go @@ -118,6 +118,19 @@ func (m *Matcher) Match(file string) (result bool) { return false } +// Patterns return a list of the loaded regexp patterns, as strings +func (m *Matcher) Patterns() []string { + patterns := make([]string, len(m.patterns)) + for i, pat := range m.patterns { + if pat.include { + patterns[i] = pat.match.String() + } else { + patterns[i] = "(?exclude)" + pat.match.String() + } + } + return patterns +} + func loadIgnoreFile(file string, seen map[string]bool) (*Matcher, error) { if seen[file] { return nil, fmt.Errorf("Multiple include of ignore file %q", file) diff --git a/internal/model/model.go b/internal/model/model.go index 2650e9ee4..8f9e1e4e9 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -730,23 +730,23 @@ func (m *Model) ConnectedTo(deviceID protocol.DeviceID) bool { return ok } -func (m *Model) GetIgnores(folder string) ([]string, error) { +func (m *Model) GetIgnores(folder string) ([]string, []string, error) { var lines []string m.fmut.RLock() cfg, ok := m.folderCfgs[folder] m.fmut.RUnlock() if !ok { - return lines, fmt.Errorf("Folder %s does not exist", folder) + return lines, nil, fmt.Errorf("Folder %s does not exist", folder) } fd, err := os.Open(filepath.Join(cfg.Path, ".stignore")) if err != nil { if os.IsNotExist(err) { - return lines, nil + return lines, nil, nil } l.Warnln("Loading .stignore:", err) - return lines, err + return lines, nil, err } defer fd.Close() @@ -755,7 +755,12 @@ func (m *Model) GetIgnores(folder string) ([]string, error) { lines = append(lines, strings.TrimSpace(scanner.Text())) } - return lines, nil + var patterns []string + if matcher := m.folderIgnores[folder]; matcher != nil { + patterns = matcher.Patterns() + } + + return lines, patterns, nil } func (m *Model) SetIgnores(folder string, content []string) error {