Merge pull request #1892 from Stell0/1891

Expand Glob (wildcards character) in paths in file in --files-from
This commit is contained in:
Alexander Neumann 2018-10-03 12:05:55 +02:00
commit a20d4bc6b0
3 changed files with 25 additions and 1 deletions

View file

@ -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

View file

@ -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")
}

View file

@ -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 {