mirror of
https://github.com/restic/restic.git
synced 2026-05-02 17:15:22 +00:00
Bugfix restic find: missing check for mtime --oldest/--newest (#5310)
This commit is contained in:
committed by
GitHub
parent
27c560b371
commit
8b567a9270
@@ -0,0 +1,7 @@
|
||||
Bugfix: `restic find` now checks for correct ordering of time related options
|
||||
|
||||
`restic find` now immediately fails with an error if both `--oldest` and `--newest` are specified
|
||||
and `--oldest` is a timestamp after `--newest`.
|
||||
|
||||
https://github.com/restic/restic/issues/5280
|
||||
https://github.com/restic/restic/pull/5310
|
||||
@@ -608,6 +608,10 @@ func runFind(ctx context.Context, opts FindOptions, gopts global.Options, args [
|
||||
}
|
||||
}
|
||||
|
||||
if !pat.newest.IsZero() && !pat.oldest.IsZero() && pat.oldest.After(pat.newest) {
|
||||
return errors.Fatal("--oldest must specify a time before --newest")
|
||||
}
|
||||
|
||||
// Check at most only one kind of IDs is provided: currently we
|
||||
// can't mix types
|
||||
if (opts.BlobID && opts.TreeID) ||
|
||||
|
||||
@@ -132,3 +132,12 @@ func TestFindSorting(t *testing.T) {
|
||||
rtest.Assert(t, matches[0].SnapshotID == matchesReverse[1].SnapshotID, "matches should be sorted 1")
|
||||
rtest.Assert(t, matches[1].SnapshotID == matchesReverse[0].SnapshotID, "matches should be sorted 2")
|
||||
}
|
||||
|
||||
func TestFindInvalidTimeRange(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
err := runFind(context.TODO(), FindOptions{Oldest: "2026-01-01", Newest: "2020-01-01"}, env.gopts, []string{"quack"}, env.gopts.Term)
|
||||
rtest.Assert(t, err != nil && err.Error() == "Fatal: --oldest must specify a time before --newest",
|
||||
"unexpected error message: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user