Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework snapshot filtering #3951

Merged
merged 11 commits into from Oct 15, 2022

Conversation

MichaelEischer
Copy link
Member

@MichaelEischer MichaelEischer commented Oct 3, 2022

What does this PR change? What problem does it solve?

The code to filter snapshots is currently dispersed throughout the code. When loading a single snapshot, the special id "latest" must be handled manually (except for ls which used the code to load multiple snapshots). When loading multiple snapshots, half of the code was located in cmd/restic/find.go and the other half in internal/restic/snapshot_find.go which is rather confusing. Some of the snapshot functions also only returned the snapshot ID making it necessary to add code to load the snapshot each time.

This PR unifies the snapshot loading into three functions FindSnapshot, FindFilteredSnapshot and FindFilteredSnapshots as part of the restic package. This unification complements #3912, initSingleSnapshotFilterOptions is now always used together with FindFilteredSnapshot and initMultiSnapshotFilterOptions with FindFilteredSnapshots. This ensures consistent behavior across commands.

The user visible changes are rather minimal. The help text for dump has been fixed. And ls returns exit code 1 the snapshot cannot be loaded. Besides that some error messages have changed if a snapshot fails to load.

Was the change previously discussed in an issue or on the forum?

No.

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes.
  • [ ] I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I have run gofmt on the code in all commits.
  • All commit messages are formatted in the same style as the other commits in the repo.
  • I'm done! This pull request is ready for review.

@MichaelEischer MichaelEischer force-pushed the rework-snapshot-filter branch 2 times, most recently from 382805d to f903e17 Compare October 15, 2022 11:23
@MichaelEischer
Copy link
Member Author

LGTM.

…pshotIDs

FindFilteredSnapshots no longer prints errors during snapshot loading on
stderr, but instead passes the error to the callback to allow the caller
to decide on what to do.

In addition, it moves the logic to handle an explicit snapshot list from
the main package to restic.
Use restic.FindFilteredSnapshot to resolve the snapshot ID. This ensures
consistent behavior for all commands using initSingleSnapshotFilterOptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant