Skip to content

Commit bfa326a

Browse files
oci: update/move a comment in tarfile handling
This comment is an overview, so move it to a higher level. Change it a bit to make it more accurate. Also: move the declaration of the buffer outside of the loop body to avoid having to re-zero it each time.
1 parent f284e33 commit bfa326a

File tree

1 file changed

+7
-6
lines changed
  • crates/composefs-oci/src

1 file changed

+7
-6
lines changed

crates/composefs-oci/src/tar.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,20 @@ fn symlink_target_from_tar(pax: Option<Box<[u8]>>, gnu: Vec<u8>, short: &[u8]) -
198198
pub fn get_entry<R: Read, ObjectID: FsVerityHashValue>(
199199
reader: &mut SplitStreamReader<R, ObjectID>,
200200
) -> Result<Option<TarEntry<ObjectID>>> {
201+
// We don't have a way to drive the standard tar crate that lets us feed it random bits of
202+
// header data while continuing to handle the external references as references. That means we
203+
// have to do the header interpretation ourselves, including handling of PAX/GNU extensions for
204+
// xattrs and long filenames.
205+
//
206+
// We try to use as much of the tar crate as possible to help us with this.
201207
let mut gnu_longlink: Vec<u8> = vec![];
202208
let mut gnu_longname: Vec<u8> = vec![];
203209
let mut pax_longlink: Option<Box<[u8]>> = None;
204210
let mut pax_longname: Option<Box<[u8]>> = None;
205211
let mut xattrs = BTreeMap::new();
206212

213+
let mut buf = [0u8; 512];
207214
loop {
208-
let mut buf = [0u8; 512];
209215
if !reader.read_inline_exact(&mut buf)? || buf == [0u8; 512] {
210216
return Ok(None);
211217
}
@@ -228,11 +234,6 @@ pub fn get_entry<R: Read, ObjectID: FsVerityHashValue>(
228234
SplitStreamData::Inline(content) => match header.entry_type() {
229235
EntryType::GNULongLink => {
230236
gnu_longlink.extend(content);
231-
232-
// NOTE: We use a custom tar parser since splitstreams are not actual tar archives
233-
// The `tar` crate does have a higher level `path` function that would do this for us.
234-
// See: https://github.com/alexcrichton/tar-rs/blob/a1c3036af48fa02437909112239f0632e4cfcfae/src/header.rs#L1532
235-
// Similar operation is performed for GNULongName
236237
gnu_longlink.pop_if(|x| *x == b'\0');
237238

238239
continue;

0 commit comments

Comments
 (0)