1
0
mirror of https://github.com/restic/restic.git synced 2024-06-22 07:26:38 +02:00

Rename FilenameCheck to RejectFunc

We already have the opposite: pipe.SelectFunc(item string, fi
os.FileInfo) bool, so RejectFunc is a good name.
This commit is contained in:
Alexander Neumann 2017-09-10 14:18:25 +02:00
parent c22c582546
commit d937ad8cf6

View File

@ -426,7 +426,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
opts.ExcludeIfPresent = append(opts.ExcludeIfPresent, "CACHEDIR.TAG:Signature: 8a477f597d28d172789f06886806bc55") opts.ExcludeIfPresent = append(opts.ExcludeIfPresent, "CACHEDIR.TAG:Signature: 8a477f597d28d172789f06886806bc55")
} }
var excludesByFile []FilenameCheck var excludesByFile []RejectFunc
for _, spec := range opts.ExcludeIfPresent { for _, spec := range opts.ExcludeIfPresent {
f, err := excludeByFile(spec) f, err := excludeByFile(spec)
if err != nil { if err != nil {
@ -448,7 +448,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
} }
for _, excludeByFile := range excludesByFile { for _, excludeByFile := range excludesByFile {
if excludeByFile(item) { if excludeByFile(item, fi) {
debug.Log("path %q excluded by tagfile", item) debug.Log("path %q excluded by tagfile", item)
return false return false
} }
@ -550,18 +550,19 @@ func readExcludePatternsFromFiles(excludeFiles []string) []string {
return excludes return excludes
} }
// FilenameCheck is a function that takes a filename and returns a boolean // RejectFunc is a function that takes a filename and os.FileInfo of a
// depending on arbitrary check. // file that would be included in the backup. The function returns true if it
type FilenameCheck func(filename string) bool // should be excluded (rejected) from the backup.
type RejectFunc func(filename string, fi os.FileInfo) bool
// excludeByFile returns a FilenameCheck which itself returns whether a path // excludeByFile returns a FilenameCheck which itself returns whether a path
// should be excluded. The FilenameCheck considers a file to be excluded when // should be excluded. The FilenameCheck considers a file to be excluded when
// it resides in a directory with an exclusion file, that is specified by // it resides in a directory with an exclusion file, that is specified by
// excludeFileSpec in the form "filename[:content]". The returned error is // excludeFileSpec in the form "filename[:content]". The returned error is
// non-nil if the filename component of excludeFileSpec is empty. // non-nil if the filename component of excludeFileSpec is empty.
func excludeByFile(excludeFileSpec string) (FilenameCheck, error) { func excludeByFile(excludeFileSpec string) (RejectFunc, error) {
if excludeFileSpec == "" { if excludeFileSpec == "" {
return func(string) bool { return false }, nil return func(string, os.FileInfo) bool { return false }, nil
} }
colon := strings.Index(excludeFileSpec, ":") colon := strings.Index(excludeFileSpec, ":")
if colon == 0 { if colon == 0 {
@ -575,7 +576,7 @@ func excludeByFile(excludeFileSpec string) (FilenameCheck, error) {
tf = excludeFileSpec tf = excludeFileSpec
} }
debug.Log("using %q as exclusion tagfile", tf) debug.Log("using %q as exclusion tagfile", tf)
fn := func(filename string) bool { fn := func(filename string, _ os.FileInfo) bool {
return isExcludedByFile(filename, tf, tc) return isExcludedByFile(filename, tf, tc)
} }
return fn, nil return fn, nil