From fb74de63602c9556c114260b54cef3d7890ebaa9 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 18 Jul 2018 21:39:07 +0200 Subject: [PATCH 1/2] Return an error when exclude files cannot be read --- cmd/restic/cmd_backup.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 11f1514e8..a1b5981ea 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -210,7 +210,11 @@ func collectRejectFuncs(opts BackupOptions, repo *repository.Repository, targets // add patterns from file if len(opts.ExcludeFiles) > 0 { - opts.Excludes = append(opts.Excludes, readExcludePatternsFromFiles(opts.ExcludeFiles)...) + excludes, err := readExcludePatternsFromFiles(opts.ExcludeFiles) + if err != nil { + return nil, err + } + opts.Excludes = append(opts.Excludes, excludes...) } if len(opts.Excludes) > 0 { @@ -238,7 +242,7 @@ func collectRejectFuncs(opts BackupOptions, repo *repository.Repository, targets // and comment lines are ignored. For each remaining pattern, environment // variables are resolved. For adding a literal dollar sign ($), write $$ to // the file. -func readExcludePatternsFromFiles(excludeFiles []string) []string { +func readExcludePatternsFromFiles(excludeFiles []string) ([]string, error) { getenvOrDollar := func(s string) string { if s == "$" { return "$" @@ -274,11 +278,10 @@ func readExcludePatternsFromFiles(excludeFiles []string) []string { return scanner.Err() }() if err != nil { - Warnf("error reading exclude patterns: %v:", err) - return nil + return nil, err } } - return excludes + return excludes, nil } // collectTargets returns a list of target files/dirs from several sources. From d7551d7b0ce5780d2b8b8e23e806945cf0d1a73e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 18 Jul 2018 21:41:20 +0200 Subject: [PATCH 2/2] Add entry to changelog --- changelog/unreleased/issue-1893 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/issue-1893 diff --git a/changelog/unreleased/issue-1893 b/changelog/unreleased/issue-1893 new file mode 100644 index 000000000..efe39c2b6 --- /dev/null +++ b/changelog/unreleased/issue-1893 @@ -0,0 +1,8 @@ +Bugfix: Return error when exclude file cannot be read + +A bug was found: when multiple exclude files were passed to restic and one of +them could not be read, an error was printed and restic continued, ignoring +even the existing exclude files. Now, an error message is printed and restic +aborts when an exclude file cannot be read. + +https://github.com/restic/restic/issues/1893