mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
Add list of compiled regexps to /rest/ignores (fixes #942)
This commit is contained in:
parent
ae0e56e98d
commit
2449723a1c
@ -476,13 +476,15 @@ func restGetIgnores(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|||||||
qs := r.URL.Query()
|
qs := r.URL.Query()
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
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 {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(map[string][]string{
|
json.NewEncoder(w).Encode(map[string][]string{
|
||||||
"ignore": ignores,
|
"ignore": ignores,
|
||||||
|
"patterns": patterns,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +118,19 @@ func (m *Matcher) Match(file string) (result bool) {
|
|||||||
return false
|
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) {
|
func loadIgnoreFile(file string, seen map[string]bool) (*Matcher, error) {
|
||||||
if seen[file] {
|
if seen[file] {
|
||||||
return nil, fmt.Errorf("Multiple include of ignore file %q", file)
|
return nil, fmt.Errorf("Multiple include of ignore file %q", file)
|
||||||
|
@ -730,23 +730,23 @@ func (m *Model) ConnectedTo(deviceID protocol.DeviceID) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) GetIgnores(folder string) ([]string, error) {
|
func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
|
||||||
var lines []string
|
var lines []string
|
||||||
|
|
||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
cfg, ok := m.folderCfgs[folder]
|
cfg, ok := m.folderCfgs[folder]
|
||||||
m.fmut.RUnlock()
|
m.fmut.RUnlock()
|
||||||
if !ok {
|
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"))
|
fd, err := os.Open(filepath.Join(cfg.Path, ".stignore"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return lines, nil
|
return lines, nil, nil
|
||||||
}
|
}
|
||||||
l.Warnln("Loading .stignore:", err)
|
l.Warnln("Loading .stignore:", err)
|
||||||
return lines, err
|
return lines, nil, err
|
||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
@ -755,7 +755,12 @@ func (m *Model) GetIgnores(folder string) ([]string, error) {
|
|||||||
lines = append(lines, strings.TrimSpace(scanner.Text()))
|
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 {
|
func (m *Model) SetIgnores(folder string, content []string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user