forked from TrueCloudLab/restic
Merge pull request #217 from restic/fix-128
cmd_backup: filter non-existing target files/dirs
This commit is contained in:
commit
50f9c20987
1 changed files with 25 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -202,6 +203,25 @@ func findLatestSnapshot(repo *repository.Repository, targets []string) (backend.
|
|||
return latestID, nil
|
||||
}
|
||||
|
||||
// filterExisting returns a slice of all existing items, or an error if no
|
||||
// items exist at all.
|
||||
func filterExisting(items []string) (result []string, err error) {
|
||||
for _, item := range items {
|
||||
_, err := os.Lstat(item)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, item)
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return nil, errors.New("all target directories/files do not exist")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (cmd CmdBackup) Execute(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
|
||||
|
@ -215,6 +235,11 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||
target = append(target, d)
|
||||
}
|
||||
|
||||
target, err := filterExisting(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue