[linux] Tests: an archive made with 'tar -C dir -czf x .' (a ./ root entry) is accepted (red: found by the systemd container test)

This commit is contained in:
2026-11-17 13:10:24 +01:00
parent 21b11cc3ef
commit b4e63423c9
2 changed files with 38 additions and 0 deletions
+33
View File
@@ -129,3 +129,36 @@ fn bad_app_or_version_names_never_reach_the_disk() {
);
}
}
#[test]
fn an_archive_made_with_tar_dot_is_accepted() {
// `tar -C dir -czf x.tar.gz .` puts the root itself first, as `./`.
let (_d, l) = layout();
let mut b = tar::Builder::new(flate2::write::GzEncoder::new(
Vec::new(),
flate2::Compression::fast(),
));
let mut dir = tar::Header::new_gnu();
dir.set_entry_type(tar::EntryType::Directory);
dir.set_mode(0o755);
dir.set_size(0);
b.append_data(&mut dir, "./", &[][..]).unwrap();
let mut f = tar::Header::new_gnu();
f.set_entry_type(tar::EntryType::Regular);
f.set_mode(0o755);
f.set_size(3);
b.append_data(
&mut f,
"./run.sh",
&b"#!
"[..],
)
.unwrap();
let a = b.into_inner().unwrap().finish().unwrap();
let dir = unpack(&l, "demo", "1.0.0", &a[..], "s").unwrap();
assert_eq!(
std::fs::read(dir.join("run.sh")).unwrap(),
b"#!
"
);
}