Skip to content

repository: enforce correct usage of SaveBlob#5558

Merged
MichaelEischer merged 2 commits into
restic:masterfrom
MichaelEischer:simplify-blob-upload
Nov 16, 2025
Merged

repository: enforce correct usage of SaveBlob#5558
MichaelEischer merged 2 commits into
restic:masterfrom
MichaelEischer:simplify-blob-upload

Conversation

@MichaelEischer

Copy link
Copy Markdown
Member

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

Uploading new blobs requires quite bit of boilerplate code. To reduce it replace StartPackUploader+Flush with WithBlobUploader . The latter handles the setup and flushing automatically.

Then move the SaveBlob method into the helper returned by WithBlobUploader. This ensures that SaveBlob cannot be called while the repository is not ready for it (well, strictly speaking the callback passed to WithBlobUploader could leak a reference to SaveBlob. However, there's no way to statically enforce this in Go).

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

No. Noticed this while making preparations for #2446 .

Checklist

  • 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'm done! This pull request is ready for review.

The new method combines both step into a single wrapper function. Thus
it ensures that both are always called in pairs. As an additional
benefit this slightly reduces the boilerplate to upload blobs.
This is achieved by removing SaveBlob from the public API and only
returning it via a uploader object that is passed in by
WithBlobUploader.

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@MichaelEischer MichaelEischer merged commit 0624b65 into restic:master Nov 16, 2025
22 of 24 checks passed
@MichaelEischer MichaelEischer deleted the simplify-blob-upload branch November 16, 2025 11:51
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.

1 participant