Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/src/tar/write: make sure we add the links when filtering the tar #251

Merged
merged 1 commit into from
Feb 21, 2022
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
18 changes: 17 additions & 1 deletion lib/src/tar/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,23 @@ pub(crate) fn filter_tar(
};

let mut header = entry.header().clone();
dest.append_data(&mut header, normalized, entry)?;

// Need to use the entry.link_name() not the header.link_name()
// api as the header api does not handle long paths:
// https://github.com/alexcrichton/tar-rs/issues/192
match entry.header().entry_type() {
tar::EntryType::Link | tar::EntryType::Symlink => {
let target = entry.link_name()?.ok_or_else(|| anyhow!("Invalid link"))?;
let target = target
.as_os_str()
.to_str()
.ok_or_else(|| anyhow!("Non-utf8 link"))?;
dest.append_link(&mut header, &normalized, target)?;
}
_ => {
dest.append_data(&mut header, normalized, entry)?;
}
}
}
dest.into_inner()?.flush()?;
Ok(filtered)
Expand Down
Binary file added lib/tests/it/fixtures/hlinks.tar.gz
Binary file not shown.
11 changes: 11 additions & 0 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::process::Command;

use fixture::Fixture;

const EXAMPLE_TAR_LAYER: &[u8] = include_bytes!("fixtures/hlinks.tar.gz");
const EXAMPLEOS_CONTENT_CHECKSUM: &str =
"0ef7461f9db15e1d8bd8921abf20694225fbaa4462cadf7deed8ea0e43162120";
const TEST_REGISTRY_DEFAULT: &str = "localhost:5000";
Expand Down Expand Up @@ -324,6 +325,16 @@ async fn test_tar_write() -> Result<()> {
Ok(())
}

#[tokio::test]
async fn test_tar_write_tar_layer() -> Result<()> {
let fixture = Fixture::new()?;
let uncompressed_tar = tokio::io::BufReader::new(
async_compression::tokio::bufread::GzipDecoder::new(EXAMPLE_TAR_LAYER),
);
ostree_ext::tar::write_tar(&fixture.destrepo, uncompressed_tar, "test", None).await?;
Ok(())
}

fn skopeo_inspect(imgref: &str) -> Result<String> {
let out = Command::new("skopeo")
.args(&["inspect", imgref])
Expand Down