diff --git a/changelog/unreleased/pull-1891 b/changelog/unreleased/pull-1891 new file mode 100644 index 000000000..b70900a93 --- /dev/null +++ b/changelog/unreleased/pull-1891 @@ -0,0 +1,7 @@ +Enhancement: Accept glob in paths loaded via --files-from + +Before that, behaviour was different if paths were appended to command line or +from a file, because wild card characters were expanded by shell if appended to +command line, but not expanded if loaded from file. + +https://github.com/restic/restic/issues/1891 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 290a31ba1..a8de4bd4f 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -4,8 +4,10 @@ import ( "bufio" "bytes" "context" + "fmt" "io/ioutil" "os" + "path/filepath" "strconv" "strings" "time" @@ -301,10 +303,21 @@ func collectTargets(opts BackupOptions, args []string) (targets []string, err er return nil, err } + // expand wildcards + var lines []string + for _, line := range fromfile { + var expanded []string + expanded, err := filepath.Glob(line) + if err != nil { + return nil, errors.WithMessage(err, fmt.Sprintf("pattern: %s", line)) + } + lines = append(lines, expanded...) + } + // merge files from files-from into normal args so we can reuse the normal // args checks and have the ability to use both files-from and args at the // same time - args = append(args, fromfile...) + args = append(args, lines...) if len(args) == 0 && !opts.Stdin { return nil, errors.Fatal("nothing to backup, please specify target files/dirs") } diff --git a/internal/errors/errors.go b/internal/errors/errors.go index aa2ff6f2b..ffd3d615e 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -22,6 +22,10 @@ var Wrap = errors.Wrap // nil, Wrapf returns nil. var Wrapf = errors.Wrapf +// WithMessage annotates err with a new message. If err is nil, WithMessage +// returns nil. +var WithMessage = errors.WithMessage + // Cause returns the cause of an error. It will also unwrap certain errors, // e.g. *url.Error returned by the net/http client. func Cause(err error) error {