lib/ignore: Add central check for internal files, used in scanning, pulling and requests

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3779
This commit is contained in:
Jakob Borg
2016-12-01 14:00:11 +00:00
committed by Audrius Butkevicius
parent 7157917a16
commit e3cf718998
4 changed files with 72 additions and 17 deletions

View File

@@ -401,3 +401,20 @@ func parseIgnoreFile(fd io.Reader, currentFile string, modtimes map[string]time.
return patterns, nil
}
// IsInternal returns true if the file, as a path relative to the folder
// root, represents an internal file that should always be ignored. The file
// path must be clean (i.e., in canonical shortest form).
func IsInternal(file string) bool {
internals := []string{".stfolder", ".stignore", ".stversions"}
pathSep := string(os.PathSeparator)
for _, internal := range internals {
if file == internal {
return true
}
if strings.HasPrefix(file, internal+pathSep) {
return true
}
}
return false
}