mirror of https://github.com/restic/restic.git
Merge pull request #1892 from Stell0/1891
Expand Glob (wildcards character) in paths in file in --files-from
This commit is contained in:
commit
a20d4bc6b0
|
@ -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
|
|
@ -4,8 +4,10 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -301,10 +303,21 @@ func collectTargets(opts BackupOptions, args []string) (targets []string, err er
|
||||||
return nil, err
|
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
|
// 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
|
// args checks and have the ability to use both files-from and args at the
|
||||||
// same time
|
// same time
|
||||||
args = append(args, fromfile...)
|
args = append(args, lines...)
|
||||||
if len(args) == 0 && !opts.Stdin {
|
if len(args) == 0 && !opts.Stdin {
|
||||||
return nil, errors.Fatal("nothing to backup, please specify target files/dirs")
|
return nil, errors.Fatal("nothing to backup, please specify target files/dirs")
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,10 @@ var Wrap = errors.Wrap
|
||||||
// nil, Wrapf returns nil.
|
// nil, Wrapf returns nil.
|
||||||
var Wrapf = errors.Wrapf
|
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,
|
// Cause returns the cause of an error. It will also unwrap certain errors,
|
||||||
// e.g. *url.Error returned by the net/http client.
|
// e.g. *url.Error returned by the net/http client.
|
||||||
func Cause(err error) error {
|
func Cause(err error) error {
|
||||||
|
|
Loading…
Reference in New Issue