Skip to content

unencapsulate: Wrap decompressor and implement Drop #1247

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

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

jeckersb
Copy link
Collaborator

@jeckersb jeckersb commented Apr 1, 2025

Followup to #1228

We use the decompressor a couple of times in unencapsulate_base in
addition to the previous fix in filter_tar_async. Instead of
duplicating the decompressor flush logic in each place, wrap the
decompressor in a struct and implement Drop for it so we always
automatically flush the input stream when we're finished with it.

Signed-off-by: John Eckersberg jeckersb@redhat.com

Followup to bootc-dev#1228

We use the decompressor a couple of times in unencapsulate_base in
addition to the previous fix in filter_tar_async.  Instead of
duplicating the decompressor flush logic in each place, wrap the
decompressor in a struct and implement Drop for it so we always
automatically flush the input stream when we're finished with it.

Signed-off-by: John Eckersberg <jeckersb@redhat.com>

let mut sink = std::io::sink();
match std::io::copy(&mut self.inner, &mut sink) {
Err(e) => tracing::debug!("Ignoring error while dropping decompressor: {e}"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about as a followup we add a method fn finish(self) -> std::io::Result<()> so we can propagate any errors here instead of ignoring them?

This is a general pattern in Rust, a similar reference example is https://doc.rust-lang.org/std/io/struct.BufWriter.html#method.into_inner

Then we update the callers of decompress to invoke .finish()?; by default.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See

fn impl_close(&mut self) -> Result<()> {
for prior art

@cgwalters
Copy link
Collaborator

I'd be a bit happier with a dedicated test but LGTM

@cgwalters cgwalters merged commit 7593910 into bootc-dev:main Apr 2, 2025
23 checks passed
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.

2 participants