From e2da0a416c1ef82e2ba94fc54651a23e5e07cf44 Mon Sep 17 00:00:00 2001 From: Stefano Fancello Date: Wed, 18 Jul 2018 18:26:24 +0200 Subject: [PATCH 1/4] Expand Glob (wildcards character) in paths in file in --files-from --- cmd/restic/cmd_backup.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 290a31ba1..5c4e1b563 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -6,6 +6,7 @@ import ( "context" "io/ioutil" "os" + "path/filepath" "strconv" "strings" "time" @@ -301,10 +302,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, err + } + 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") } From d1df3718b536e143a40841541cd46b74eb06199f Mon Sep 17 00:00:00 2001 From: Stefano Fancello Date: Thu, 19 Jul 2018 12:04:03 +0200 Subject: [PATCH 2/4] Add changelog unreleased file --- changelog/unreleased/pull-1891 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/pull-1891 diff --git a/changelog/unreleased/pull-1891 b/changelog/unreleased/pull-1891 new file mode 100644 index 000000000..d9c6aee9e --- /dev/null +++ b/changelog/unreleased/pull-1891 @@ -0,0 +1,6 @@ +Enhancement: Accept glob in paths that are in file loaded with --file-from + +Before that, behaviour was different if paths were appended to command line or from a file, because wildcard characters were expanded by shell if appended to command line, but not expanded if loaded from file +https://github.com/restic/restic/issues/1891 + + From 33dfbf5c386803721cdc9d6ff2736cb3e9c12ab2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 3 Oct 2018 10:34:50 +0200 Subject: [PATCH 3/4] Reword changelog --- changelog/unreleased/pull-1891 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/changelog/unreleased/pull-1891 b/changelog/unreleased/pull-1891 index d9c6aee9e..b70900a93 100644 --- a/changelog/unreleased/pull-1891 +++ b/changelog/unreleased/pull-1891 @@ -1,6 +1,7 @@ -Enhancement: Accept glob in paths that are in file loaded with --file-from +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. -Before that, behaviour was different if paths were appended to command line or from a file, because wildcard characters were expanded by shell if appended to command line, but not expanded if loaded from file https://github.com/restic/restic/issues/1891 - - From fb31d6695159b5133debdbfbed5ef1db9aab405a Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 3 Oct 2018 11:12:51 +0200 Subject: [PATCH 4/4] backup: Improve error message for invalid pattern --- cmd/restic/cmd_backup.go | 3 ++- internal/errors/errors.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 5c4e1b563..a8de4bd4f 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "fmt" "io/ioutil" "os" "path/filepath" @@ -308,7 +309,7 @@ func collectTargets(opts BackupOptions, args []string) (targets []string, err er var expanded []string expanded, err := filepath.Glob(line) if err != nil { - return nil, err + return nil, errors.WithMessage(err, fmt.Sprintf("pattern: %s", line)) } lines = append(lines, expanded...) } 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 {