Repository navigation
unencapsulate: Wrap decompressor and implement Drop - #1247
Merged
Merged
Conversation
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]>
cgwalters
approved these changes
Apr 2, 2025
|
|
||
| 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}"), |
Member
There was a problem hiding this comment.
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.
Member
There was a problem hiding this comment.
See
bootc/blockdev/src/blockdev.rs
Line 221 in 7593910
Member
|
I'd be a bit happier with a dedicated test but LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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]