Skip to content

Commit

Permalink
Merge pull request #201 from nichmor/fix/soft-links-should-remain-the…
Browse files Browse the repository at this point in the history
…-same

fix: soft links should remain the same
  • Loading branch information
Pr0methean authored Jul 18, 2024
2 parents 03dd557 + bde1bb9 commit 6106a2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ impl<R: Read + Seek> ZipArchive<R> {
}
let symlink_target = if file.is_symlink() && (cfg!(unix) || cfg!(windows)) {
let mut target = Vec::with_capacity(file.size() as usize);
file.read_exact(&mut target)?;
file.read_to_end(&mut target)?;
Some(target)
} else {
None
Expand All @@ -1097,8 +1097,7 @@ impl<R: Read + Seek> ZipArchive<R> {
{
use std::os::unix::ffi::OsStringExt;
let target = OsString::from_vec(target);
let target_path = directory.as_ref().join(target);
std::os::unix::fs::symlink(target_path, outpath.as_path())?;
std::os::unix::fs::symlink(&target, outpath.as_path())?;
}
#[cfg(windows)]
{
Expand Down
Binary file added tests/data/pandoc_soft_links.zip
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/extract_symlink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[test]
#[cfg(all(unix, feature = "_deflate-any"))]
fn extract_should_respect_links() {
use std::{fs, io, path::PathBuf, str::FromStr};
use tempdir::TempDir;
use zip::ZipArchive;

let mut v = Vec::new();
v.extend_from_slice(include_bytes!("data/pandoc_soft_links.zip"));
let mut archive = ZipArchive::new(io::Cursor::new(v)).expect("couldn't open test zip file");
let temp_dir = TempDir::new("pandoc_soft_links").unwrap();
archive.extract(&temp_dir).unwrap();

let symlink_path = temp_dir.path().join("pandoc-3.2-arm64/bin/pandoc-lua");

// Read the target of the symbolic link
let target_path = fs::read_link(&symlink_path).unwrap();

assert_eq!(target_path, PathBuf::from_str("pandoc").unwrap());
}

0 comments on commit 6106a2b

Please sign in to comment.