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

Add seekable method for TarReader use to determine whether the current reader supports seek #1411

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion builder/src/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ impl Read for TarReader {
}
}

impl TarReader {
fn seekable(&self) -> bool {
matches!(
self,
TarReader::File(_) | TarReader::BufReaderInfoSeekable(_)
)
}
}

impl Seek for TarReader {
fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
match self {
Expand Down Expand Up @@ -183,6 +192,8 @@ impl<'a> TarballTreeBuilder<'a> {
}
_ => return Err(anyhow!("tarball: unsupported image conversion type")),
};

let is_seekable = reader.seekable();
let mut tar = Archive::new(reader);
tar.set_ignore_zeros(true);
tar.set_preserve_mtime(true);
Expand All @@ -199,7 +210,7 @@ impl<'a> TarballTreeBuilder<'a> {
let mut tree = Tree::new(root);

// Generate RAFS node for each tar entry, and optionally adding missing parents.
let entries = if is_file {
let entries = if is_seekable {
tar.entries_with_seek()
.context("tarball: failed to read entries from tar")?
} else {
Expand Down