From 8b567a9270b97b854c75955f3f2332408da4ddcb Mon Sep 17 00:00:00 2001 From: Winfried Plappert <18740761+wplapper@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:14:35 +0000 Subject: [PATCH] Bugfix `restic find`: missing check for mtime --oldest/--newest (#5310) --- changelog/unreleased/issue-5280 | 7 +++++++ cmd/restic/cmd_find.go | 4 ++++ cmd/restic/cmd_find_integration_test.go | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 changelog/unreleased/issue-5280 diff --git a/changelog/unreleased/issue-5280 b/changelog/unreleased/issue-5280 new file mode 100644 index 000000000..9714e3c43 --- /dev/null +++ b/changelog/unreleased/issue-5280 @@ -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 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 0ae7e315d..c4107222d 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -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) || diff --git a/cmd/restic/cmd_find_integration_test.go b/cmd/restic/cmd_find_integration_test.go index 360620952..c7479a4f8 100644 --- a/cmd/restic/cmd_find_integration_test.go +++ b/cmd/restic/cmd_find_integration_test.go @@ -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) +}