mirror of
https://github.com/octoleo/restic.git
synced 2024-11-27 07:16:40 +00:00
archiver: move helper functions to combine rejects
This commit is contained in:
parent
f1585af0f2
commit
6fd5d5f2d5
@ -529,21 +529,11 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
|||||||
}
|
}
|
||||||
|
|
||||||
bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term)
|
bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term)
|
||||||
|
|
||||||
err = repo.LoadIndex(ctx, bar)
|
err = repo.LoadIndex(ctx, bar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
selectByNameFilter := func(item string) bool {
|
|
||||||
for _, reject := range rejectByNameFuncs {
|
|
||||||
if reject(item) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var targetFS fs.FS = fs.Local{}
|
var targetFS fs.FS = fs.Local{}
|
||||||
if runtime.GOOS == "windows" && opts.UseFsSnapshot {
|
if runtime.GOOS == "windows" && opts.UseFsSnapshot {
|
||||||
if err = fs.HasSufficientPrivilegesForVSS(); err != nil {
|
if err = fs.HasSufficientPrivilegesForVSS(); err != nil {
|
||||||
@ -592,14 +582,8 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
selectFilter := func(item string, fi os.FileInfo, fs fs.FS) bool {
|
selectByNameFilter := archiver.CombineRejectByNames(rejectByNameFuncs)
|
||||||
for _, reject := range rejectFuncs {
|
selectFilter := archiver.CombineRejects(rejectFuncs)
|
||||||
if reject(item, fi, fs) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
wg, wgCtx := errgroup.WithContext(ctx)
|
wg, wgCtx := errgroup.WithContext(ctx)
|
||||||
cancelCtx, cancel := context.WithCancel(wgCtx)
|
cancelCtx, cancel := context.WithCancel(wgCtx)
|
||||||
|
@ -24,6 +24,28 @@ type RejectByNameFunc func(path string) bool
|
|||||||
// should be excluded (rejected) from the backup.
|
// should be excluded (rejected) from the backup.
|
||||||
type RejectFunc func(path string, fi os.FileInfo, fs fs.FS) bool
|
type RejectFunc func(path string, fi os.FileInfo, fs fs.FS) bool
|
||||||
|
|
||||||
|
func CombineRejectByNames(funcs []RejectByNameFunc) SelectByNameFunc {
|
||||||
|
return func(item string) bool {
|
||||||
|
for _, reject := range funcs {
|
||||||
|
if reject(item) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CombineRejects(funcs []RejectFunc) SelectFunc {
|
||||||
|
return func(item string, fi os.FileInfo, fs fs.FS) bool {
|
||||||
|
for _, reject := range funcs {
|
||||||
|
if reject(item, fi, fs) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type rejectionCache struct {
|
type rejectionCache struct {
|
||||||
m map[string]bool
|
m map[string]bool
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
|
Loading…
Reference in New Issue
Block a user