forked from TrueCloudLab/restic
Check error in archiver before calling Select
The archiver first called the Select function for a path before checking whether the Lstat on that path actually worked. The RejectFuncs in exclude.go worked around this by checking whether they received a nil os.FileInfo. Checking first is more obvious and requires less code.
This commit is contained in:
parent
3c6671b18b
commit
c4e2203e45
2 changed files with 4 additions and 13 deletions
|
@ -234,10 +234,6 @@ func rejectByDevice(samples []string) (RejectFunc, error) {
|
|||
debug.Log("allowed devices: %v\n", allowed)
|
||||
|
||||
return func(item string, fi os.FileInfo) bool {
|
||||
if fi == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
item = filepath.Clean(item)
|
||||
|
||||
id, err := fs.DeviceID(fi)
|
||||
|
@ -301,10 +297,6 @@ func rejectBySize(maxSizeStr string) (RejectFunc, error) {
|
|||
}
|
||||
|
||||
return func(item string, fi os.FileInfo) bool {
|
||||
if fi == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// directory will be ignored
|
||||
if fi.IsDir() {
|
||||
return false
|
||||
|
|
|
@ -345,11 +345,6 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
|||
|
||||
// get file info and run remaining select functions that require file information
|
||||
fi, err := arch.FS.Lstat(target)
|
||||
if !arch.Select(abstarget, fi) {
|
||||
debug.Log("%v is excluded", target)
|
||||
return FutureNode{}, true, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
debug.Log("lstat() for %v returned error: %v", target, err)
|
||||
err = arch.error(abstarget, fi, err)
|
||||
|
@ -358,6 +353,10 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
|||
}
|
||||
return FutureNode{}, true, nil
|
||||
}
|
||||
if !arch.Select(abstarget, fi) {
|
||||
debug.Log("%v is excluded", target)
|
||||
return FutureNode{}, true, nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case fs.IsRegularFile(fi):
|
||||
|
|
Loading…
Reference in a new issue