Skip to content

Commit

Permalink
Revert "tarindex: Add special symlink name handling"
Browse files Browse the repository at this point in the history
This reverts commit 3951807.
  • Loading branch information
ms-mahuber committed Mar 20, 2024
1 parent 3541346 commit 63a379f
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/tardev-snapshotter/tarindex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fn visit_breadth_first_mut(
fn read_all_entries(
reader: &mut (impl io::Read + io::Seek),
root: &mut Rc<RefCell<Entry>>,
special_link: &mut Vec<Vec<u8>>,
mut cb: impl FnMut(&mut Rc<RefCell<Entry>>, &[u8], &Entry),
mut hardlink: impl FnMut(&mut Rc<RefCell<Entry>>, &[u8], &[u8]),
) -> io::Result<u64> {
Expand Down Expand Up @@ -137,12 +136,18 @@ fn read_all_entries(
.link_name_bytes()
.unwrap_or(std::borrow::Cow::Borrowed(b""));
if *hname != *name {
special_link.push(name.to_vec());
entry_offset = 0;
} else {
entry_offset = f.raw_header_position() + 157;
// TODO: Handle this case by duplicating the full name.
eprintln!(
"Skipping symlink with long link name ({}, {} bytes, {}, {} bytes): {}",
String::from_utf8_lossy(&name), name.len(),
String::from_utf8_lossy(&hname), hname.len(),
String::from_utf8_lossy(&f.path_bytes())
);
continue;
}

entry_size = name.len() as u64;
entry_offset = f.raw_header_position() + 157;
}
None => {
eprintln!(
Expand Down Expand Up @@ -301,11 +306,10 @@ pub fn append_index(data: &mut (impl io::Read + io::Write + io::Seek)) -> io::Re
mode: S_IFDIR | 0o555,
..Entry::default()
}));
let mut special_link = Vec::new();

let contents_size = read_all_entries(
data,
&mut root,
&mut special_link,
|root, name, e| {
// Break the name into path components.
let mut path = if let Some(p) = clean_path(name) {
Expand Down Expand Up @@ -423,23 +427,13 @@ pub fn append_index(data: &mut (impl io::Read + io::Write + io::Seek)) -> io::Re
// Calculate the offsets for directory entries.
let inode_table_size: u64 = mem::size_of::<Inode>() as u64 * ino_count;
let string_table_offset = init_direntry_offset(root.clone(), contents_size + inode_table_size)?;
let mut symlink_offset = string_table_offset;

// Write the i-node table.
visit_breadth_first_mut(root.clone(), |e| {
if e.emitted {
return Ok(());
}

// Check for special symlink names
let inode_offset = if (e.mode & S_IFMT) != S_IFLNK || e.offset != 0 {
e.offset
} else {
let v = symlink_offset;
symlink_offset += e.size;
v
};

e.emitted = true;
let inode = Inode {
mode: e.mode.into(),
Expand All @@ -453,20 +447,14 @@ pub fn append_index(data: &mut (impl io::Read + io::Write + io::Seek)) -> io::Re
group: e.group.into(),
lmtime: (e.mtime as u32).into(),
size: e.size.into(),
offset: inode_offset.into(),
offset: e.offset.into(),
};
data.write_all(inode.as_bytes())?;
Ok(())
})?;

// Write the directory bodies.
let mut end_offset = write_direntry_bodies(root.clone(), symlink_offset, data)?;

// Duplicate special symlink names.
for link_name in special_link.iter() {
data.write_all(link_name.as_bytes())?;
end_offset += link_name.len() as u64;
}
let mut end_offset = write_direntry_bodies(root.clone(), string_table_offset, data)?;

// Write the strings.
visit_breadth_first_mut(root, |e| {
Expand Down

0 comments on commit 63a379f

Please sign in to comment.