mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Handle .stignore correctly on Windows (fixes #369)
This commit is contained in:
parent
26ebbee877
commit
874d6760d4
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by an MIT-style license that can be
|
// Use of this source code is governed by an MIT-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// +build !solaris
|
// +build !solaris,!windows
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ package scanner
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -104,13 +105,15 @@ func (w *Walker) loadIgnoreFiles(dir string, ign map[string][]string) filepath.W
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pn, sn := filepath.Split(rn); sn == w.IgnoreFile {
|
if pn, sn := filepath.Split(rn); sn == w.IgnoreFile {
|
||||||
pn := strings.Trim(pn, "/")
|
pn := filepath.Clean(pn)
|
||||||
|
l.Debugf("pn: %q", pn)
|
||||||
bs, _ := ioutil.ReadFile(p)
|
bs, _ := ioutil.ReadFile(p)
|
||||||
lines := bytes.Split(bs, []byte("\n"))
|
lines := bytes.Split(bs, []byte("\n"))
|
||||||
var patterns []string
|
var patterns []string
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if len(line) > 0 {
|
lineStr := strings.TrimSpace(string(line))
|
||||||
patterns = append(patterns, string(line))
|
if len(lineStr) > 0 {
|
||||||
|
patterns = append(patterns, lineStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ign[pn] = patterns
|
ign[pn] = patterns
|
||||||
@ -282,8 +285,9 @@ func (w *Walker) cleanTempFile(path string, info os.FileInfo, err error) error {
|
|||||||
func (w *Walker) ignoreFile(patterns map[string][]string, file string) bool {
|
func (w *Walker) ignoreFile(patterns map[string][]string, file string) bool {
|
||||||
first, last := filepath.Split(file)
|
first, last := filepath.Split(file)
|
||||||
for prefix, pats := range patterns {
|
for prefix, pats := range patterns {
|
||||||
if len(prefix) == 0 || prefix == first || strings.HasPrefix(first, prefix+"/") {
|
if prefix == "." || prefix == first || strings.HasPrefix(first, fmt.Sprintf("%s%c", prefix, os.PathSeparator)) {
|
||||||
for _, pattern := range pats {
|
for _, pattern := range pats {
|
||||||
|
l.Debugf("%q %q", pattern, last)
|
||||||
if match, _ := filepath.Match(pattern, last); match {
|
if match, _ := filepath.Match(pattern, last); match {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ var testdata = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var correctIgnores = map[string][]string{
|
var correctIgnores = map[string][]string{
|
||||||
"": {".*", "quux"},
|
".": {".*", "quux"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWalk(t *testing.T) {
|
func TestWalk(t *testing.T) {
|
||||||
@ -88,7 +88,7 @@ func TestWalkError(t *testing.T) {
|
|||||||
|
|
||||||
func TestIgnore(t *testing.T) {
|
func TestIgnore(t *testing.T) {
|
||||||
var patterns = map[string][]string{
|
var patterns = map[string][]string{
|
||||||
"": {"t2"},
|
".": {"t2"},
|
||||||
"foo": {"bar", "z*"},
|
"foo": {"bar", "z*"},
|
||||||
"foo/baz": {"quux", ".*"},
|
"foo/baz": {"quux", ".*"},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user