Skip to content

Commit

Permalink
oci: split 'get_entry()' out of 'ls' command
Browse files Browse the repository at this point in the history
This lets us read a single composefs dumpfile Entry out of the split
stream.  This is going to be the basis of merging entries from multiple
streams.

'ls' is now a positively trivial loop around get_entry() until EOF.
  • Loading branch information
allisonkarlitskaya committed Oct 10, 2024
1 parent 2e0e709 commit 85bf7a1
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/oci/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ fn symlink_target_from_tar(pax: Option<Vec<u8>>, gnu: Vec<u8>, short: &[u8]) ->
}
}

pub fn ls<R: Read>(split_stream: &mut R) -> Result<()> {
let mut reader = SplitStreamReader::new(split_stream);
fn get_entry<R: Read>(reader: &mut SplitStreamReader<R>) -> Result<Option<Entry<'static>>> {
let mut gnu_longlink: Vec<u8> = vec![];
let mut gnu_longname: Vec<u8> = vec![];
let mut pax_longlink: Option<Vec<u8>> = None;
Expand All @@ -148,12 +147,8 @@ pub fn ls<R: Read>(split_stream: &mut R) -> Result<()> {

loop {
let mut buf = [0u8; 512];
if !reader.read_inline_exact(&mut buf)? {
return Ok(());
}

if buf == [0u8; 512] {
return Ok(());
if !reader.read_inline_exact(&mut buf)? || buf == [0u8; 512] {
return Ok(None);
}

let header = tar::Header::from_byte_slice(&buf);
Expand Down Expand Up @@ -252,22 +247,22 @@ pub fn ls<R: Read>(split_stream: &mut R) -> Result<()> {
},
}.as_raw_mode();

let entry = Entry {
return Ok(Some(Entry {
path: Cow::Owned(path_from_tar(pax_longname, gnu_longname, &header.path_bytes())),
uid: header.uid()? as u32,
gid: header.gid()? as u32,
mode: header.mode()? | ifmt,
mtime: Mtime { sec: header.mtime()?, nsec: 0 },
item,
xattrs
};
}));
}
}

pub fn ls<R: Read>(split_stream: &mut R) -> Result<()> {
let mut reader = SplitStreamReader::new(split_stream);
while let Some(entry) = get_entry(&mut reader)? {
println!("{}", entry);

gnu_longlink = vec![];
gnu_longname = vec![];
pax_longlink = None;
pax_longname = None;
xattrs = vec![];
}
Ok(())
}

0 comments on commit 85bf7a1

Please sign in to comment.