Merge pull request #1858 from restic/fix-1857

Allow excluding files with $ via --exclude-file
This commit is contained in:
Alexander Neumann
2018-06-22 21:22:23 +02:00
2 changed files with 15 additions and 3 deletions

View File

@@ -234,8 +234,18 @@ func collectRejectFuncs(opts BackupOptions, repo *repository.Repository, targets
}
// readExcludePatternsFromFiles reads all exclude files and returns the list of
// exclude patterns.
// exclude patterns. For each line, leading and trailing white space is removed
// and comment lines are ignored. For each remaining pattern, environment
// variables are resolved. For adding a literal dollar sign ($), write $$ to
// the file.
func readExcludePatternsFromFiles(excludeFiles []string) []string {
getenvOrDollar := func(s string) string {
if s == "$" {
return "$"
}
return os.Getenv(s)
}
var excludes []string
for _, filename := range excludeFiles {
err := func() (err error) {
@@ -258,7 +268,7 @@ func readExcludePatternsFromFiles(excludeFiles []string) []string {
continue
}
line = os.ExpandEnv(line)
line = os.Expand(line, getenvOrDollar)
excludes = append(excludes, line)
}
return scanner.Err()