Skip to content

Commit

Permalink
fix: assure cyclic symlinks in package won't break it.
Browse files Browse the repository at this point in the history
For now we just ignore any IO error due to limitations in error
granularity, which might mean that the package size is a little off.

That's preferable over not working at all.
  • Loading branch information
Byron committed Apr 14, 2022
1 parent 5525517 commit 132307a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn tar_package_from_paths(lines: Vec<u8>) -> Result<TarPackage> {
}

const REGULAR_FILE: u8 = b'0';
if let Some(meta) = fs::metadata(&path)
if let Some(meta) = fs::symlink_metadata(&path)
.map(Some)
.or_else(|err| {
if err.kind() == std::io::ErrorKind::NotFound {
Expand Down Expand Up @@ -352,6 +352,7 @@ fn check_package_size(
let mut builder = tar::Builder::new(
flate2::GzBuilder::new().write(byte_counter, flate2::Compression::best()),
);
builder.follow_symlinks(false);
// NOTE: we are not taking generated files into consideration, but assume the space required for them is negligble
// The reason we do things in memory is to avoid having side-effects, like dropping files to disk by invoking `cargo package` directly.
let base = PathBuf::from("cratename-v0.1.0");
Expand All @@ -360,7 +361,11 @@ fn check_package_size(
let path_without_root = tar_path_to_utf8_str(&entry.path);
header.set_path(&base.join(path_without_root))?;

let mut file = std::fs::File::open(path_without_root)?;
let mut file = match std::fs::File::open(path_without_root) {
Ok(f) => f,
// Err(err) if err.kind() == std::io::ErrorKind::FilesystemLoop => continue,
Err(_) => continue, // for now ignore all errors until we can use the line above
};
let metadata = file.metadata()?;
header.set_metadata(&metadata);
header.set_cksum();
Expand Down

0 comments on commit 132307a

Please sign in to comment.