mirror of
https://github.com/restic/restic.git
synced 2024-12-28 02:38:33 +00:00
unify exclude patterns with backup command
This commit is contained in:
parent
2b69a1c53b
commit
4cace1ffe9
1 changed files with 6 additions and 27 deletions
|
@ -53,9 +53,10 @@ type RewriteOptions struct {
|
||||||
DryRun bool
|
DryRun bool
|
||||||
|
|
||||||
// Exclude options
|
// Exclude options
|
||||||
Excludes []string
|
Excludes []string
|
||||||
InsensitiveExcludes []string
|
InsensitiveExcludes []string
|
||||||
ExcludeFiles []string
|
ExcludeFiles []string
|
||||||
|
InsensitiveExcludeFiles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var rewriteOptions RewriteOptions
|
var rewriteOptions RewriteOptions
|
||||||
|
@ -74,29 +75,7 @@ func init() {
|
||||||
f.StringArrayVarP(&rewriteOptions.Excludes, "exclude", "e", nil, "exclude a `pattern` (can be specified multiple times)")
|
f.StringArrayVarP(&rewriteOptions.Excludes, "exclude", "e", nil, "exclude a `pattern` (can be specified multiple times)")
|
||||||
f.StringArrayVar(&rewriteOptions.InsensitiveExcludes, "iexclude", nil, "same as --exclude `pattern` but ignores the casing of filenames")
|
f.StringArrayVar(&rewriteOptions.InsensitiveExcludes, "iexclude", nil, "same as --exclude `pattern` but ignores the casing of filenames")
|
||||||
f.StringArrayVar(&rewriteOptions.ExcludeFiles, "exclude-file", nil, "read exclude patterns from a `file` (can be specified multiple times)")
|
f.StringArrayVar(&rewriteOptions.ExcludeFiles, "exclude-file", nil, "read exclude patterns from a `file` (can be specified multiple times)")
|
||||||
}
|
f.StringArrayVar(&rewriteOptions.InsensitiveExcludeFiles, "iexclude-file", nil, "same as --exclude-file but ignores casing of `file`names in patterns")
|
||||||
|
|
||||||
func collectRejectFuncsForRewrite(opts RewriteOptions) (fs []RejectByNameFunc, err error) {
|
|
||||||
//TODO: merge with cmd_backup
|
|
||||||
|
|
||||||
// add patterns from file
|
|
||||||
if len(opts.ExcludeFiles) > 0 {
|
|
||||||
excludes, err := readExcludePatternsFromFiles(opts.ExcludeFiles)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
opts.Excludes = append(opts.Excludes, excludes...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(opts.InsensitiveExcludes) > 0 {
|
|
||||||
fs = append(fs, rejectByInsensitivePattern(opts.InsensitiveExcludes))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(opts.Excludes) > 0 {
|
|
||||||
fs = append(fs, rejectByPattern(opts.Excludes))
|
|
||||||
}
|
|
||||||
|
|
||||||
return fs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *restic.Snapshot, opts RewriteOptions, gopts GlobalOptions) (bool, error) {
|
func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *restic.Snapshot, opts RewriteOptions, gopts GlobalOptions) (bool, error) {
|
||||||
|
@ -104,7 +83,7 @@ func rewriteSnapshot(ctx context.Context, repo *repository.Repository, sn *resti
|
||||||
return false, errors.Errorf("snapshot %v has nil tree", sn.ID().Str())
|
return false, errors.Errorf("snapshot %v has nil tree", sn.ID().Str())
|
||||||
}
|
}
|
||||||
|
|
||||||
rejectByNameFuncs, err := collectRejectFuncsForRewrite(opts)
|
rejectByNameFuncs, err := collectExcludePatterns(opts.Excludes, opts.InsensitiveExcludes, opts.ExcludeFiles, opts.InsensitiveExcludeFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue