diff options
author | Audrius Butkevicius <audrius.butkevicius@gmail.com> | 2014-08-28 23:45:26 +0100 |
---|---|---|
committer | Audrius Butkevicius <audrius.butkevicius@gmail.com> | 2014-08-31 15:32:22 +0100 |
commit | 8c42aea827f6021caa62704ff0df34e8a219a4fb (patch) | |
tree | 1d25971e653bbbd0ad8cc46d4b62f1d09b205007 | |
parent | b0408ef5c6558cb41b508d10d27f69524e6dd9d2 (diff) | |
download | syncthing-8c42aea827f6021caa62704ff0df34e8a219a4fb.tar.gz syncthing-8c42aea827f6021caa62704ff0df34e8a219a4fb.zip |
Add #include directive to .stignore (fixes #424)
Though breaks #502 in a way, as .stignore is not the only place where
stuff gets defined anymore.
Though it never was, as .stignore can be placed in each dir, but I think we
should phase that out in favor of globbing which means that we can then
have a single file, which means that we can have a UI for editing that.
Alternative would be as suggested to include a .stglobalignore which is then synced
as a normal file, but gets included by default.
Then when the UI would have two editors, a local ignore, and a global ignore.
-rw-r--r-- | scanner/walk.go | 12 | ||||
-rw-r--r-- | scanner/walk_test.go | 6 |
2 files changed, 13 insertions, 5 deletions
diff --git a/scanner/walk.go b/scanner/walk.go index 8cb189725..6008d22e8 100644 --- a/scanner/walk.go +++ b/scanner/walk.go @@ -113,10 +113,10 @@ func loadIgnoreFile(ignFile, base string) []*regexp.Regexp { return nil } defer fd.Close() - return parseIgnoreFile(fd, base) + return parseIgnoreFile(fd, base, filepath.Dir(ignFile)) } -func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp { +func parseIgnoreFile(fd io.Reader, base, dir string) []*regexp.Regexp { var exps []*regexp.Regexp scanner := bufio.NewScanner(fd) for scanner.Scan() { @@ -148,6 +148,14 @@ func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp { continue } exps = append(exps, exp) + } else if strings.HasPrefix(line, "#include ") { + includeFile := filepath.Join(dir, strings.Replace(line, "#include ", "", 1)) + if _, err := os.Stat(includeFile); os.IsNotExist(err) { + l.Infoln("Could not open ignore include file", includeFile) + } else { + includes := loadIgnoreFile(includeFile, base) + exps = append(exps, includes...) + } } else { // Path name or pattern, add it so it matches files both in // current directory and subdirs. diff --git a/scanner/walk_test.go b/scanner/walk_test.go index 943843b2a..a0ac451e0 100644 --- a/scanner/walk_test.go +++ b/scanner/walk_test.go @@ -128,20 +128,20 @@ func TestIgnore(t *testing.T) { */other/test **/deep `) - patterns := parseIgnoreFile(patStr, "") + patterns := parseIgnoreFile(patStr, "", "") patStr = bytes.NewBufferString(` bar z* q[abc]x `) - patterns = append(patterns, parseIgnoreFile(patStr, "foo")...) + patterns = append(patterns, parseIgnoreFile(patStr, "foo", "")...) patStr = bytes.NewBufferString(` quux .* `) - patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz")...) + patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz", "")...) var tests = []struct { f string |