Skip to content

unencapsulate: Wrap decompressor and implement Drop - #1247

Merged
cgwalters merged 1 commit into
bootc-dev:mainfrom
jeckersb:decompressor-flush-on-drop
Apr 2, 2025
Merged

cgwalters merged 1 commit into
bootc-dev:mainfrom
jeckersb:decompressor-flush-on-drop

Conversation

@jeckersb

@jeckersb jeckersb commented Apr 1, 2025

Copy link
Copy Markdown
Collaborator

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 [email protected]

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 <[email protected]>

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
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
Member

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

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