1
mirror of https://github.com/rclone/rclone synced 2025-04-04 22:25:31 +02:00

Fix --files-from with an empty file copying everything - fixes

This commit is contained in:
Nick Craig-Wood 2017-03-04 10:11:15 +00:00
parent 4ab7e05e02
commit 10e532bce9

@ -212,6 +212,7 @@ func NewFilter() (f *Filter, err error) {
} }
if filesFrom != nil { if filesFrom != nil {
for _, rule := range *filesFrom { for _, rule := range *filesFrom {
f.initAddFile() // init to show --files-from set even if no files within
err := forEachLine(rule, func(line string) error { err := forEachLine(rule, func(line string) error {
return f.AddFile(line) return f.AddFile(line)
}) })
@ -323,12 +324,17 @@ func (f *Filter) AddRule(rule string) error {
return errors.Errorf("malformed rule %q", rule) return errors.Errorf("malformed rule %q", rule)
} }
// AddFile adds a single file to the files from list // initAddFile creates f.files and f.dirs
func (f *Filter) AddFile(file string) error { func (f *Filter) initAddFile() {
if f.files == nil { if f.files == nil {
f.files = make(FilesMap) f.files = make(FilesMap)
f.dirs = make(FilesMap) f.dirs = make(FilesMap)
} }
}
// AddFile adds a single file to the files from list
func (f *Filter) AddFile(file string) error {
f.initAddFile()
file = strings.Trim(file, "/") file = strings.Trim(file, "/")
f.files[file] = struct{}{} f.files[file] = struct{}{}
// Put all the parent directories into f.dirs // Put all the parent directories into f.dirs