Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

tar: Fix multiple hardlinks #558

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions lib/src/tar/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ pub(crate) fn filter_tar(
dest.append_data(&mut header, path, data)?;
// And cache this file path as the new link target
new_sysroot_link_targets.insert(target.to_owned(), path.to_owned());
} else if let Some(target) = new_sysroot_link_targets.get(path) {
tracing::debug!("Relinking {path} to {target}");
} else if let Some(real_target) = new_sysroot_link_targets.get(target) {
tracing::debug!("Relinking {path} to {real_target}");
// We found a 2nd (or 3rd, etc.) link into /sysroot; rewrite the link
// target to be the first file outside of /sysroot we found.
let mut header = header.clone();
dest.append_link(&mut header, path, target)?;
dest.append_link(&mut header, path, real_target)?;
} else {
tracing::debug!("Found unhandled modified link from {path} to {target}");
}
Expand Down
24 changes: 12 additions & 12 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,12 +1261,14 @@ async fn test_container_write_derive_sysroot_hardlink() -> Result<()> {
h.set_size(data.len() as u64);
tar.append_data(&mut h, objpath, std::io::Cursor::new(data))
.context("appending object")?;
let targetpath = Utf8Path::new("usr/bin/bash");
h.set_size(0);
h.set_mtime(now);
h.set_entry_type(tar::EntryType::Link);
tar.append_link(&mut h, targetpath, objpath)
.context("appending target")?;
for path in ["usr/bin/bash", "usr/bin/bash-hardlinked"] {
let targetpath = Utf8Path::new(path);
h.set_size(0);
h.set_mtime(now);
h.set_entry_type(tar::EntryType::Link);
tar.append_link(&mut h, targetpath, objpath)
.context("appending target")?;
}
Ok::<_, anyhow::Error>(())
},
None,
Expand Down Expand Up @@ -1294,12 +1296,10 @@ async fn test_container_write_derive_sysroot_hardlink() -> Result<()> {
)
.ignore_stdout()
.run()?;
let r = cmd!(
sh,
"ostree --repo=dest/repo cat {merge_commit} /usr/bin/bash"
)
.read()?;
assert_eq!(r.as_str(), "hello");
for path in ["/usr/bin/bash", "/usr/bin/bash-hardlinked"] {
let r = cmd!(sh, "ostree --repo=dest/repo cat {merge_commit} {path}").read()?;
assert_eq!(r.as_str(), "hello");
}

Ok(())
}
Expand Down
Loading