Skip to content

Commit

Permalink
lib/src/tar/write: make sure we add the links when filtering the tar
Browse files Browse the repository at this point in the history
Co-authored-by: Colin Walters <walters@verbum.org>
  • Loading branch information
jmarrero and cgwalters committed Feb 21, 2022
1 parent 8a4b8ce commit b8dc59e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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

0 comments on commit b8dc59e

Please sign in to comment.