mirror of
https://github.com/restic/restic.git
synced 2025-12-08 23:32:17 +00:00
Allow excluding files with $ via --exclude-file
Previously it wasn't possbile to exclude files with a literal dollar sign (`$`) via exclude files, now users can write `$$` for that.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user