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

fix: soft links should remain the same #201

Merged
5 changes: 2 additions & 3 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@
}
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 @@ -1020,8 +1020,7 @@
{
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 Expand Up @@ -1604,7 +1603,7 @@
/// `foo/../bar` as `foo/bar` (instead of `bar`). Because of this,
/// [`ZipFile::enclosed_name`] is the better option in most scenarios.
///
/// [`ParentDir`]: `Component::ParentDir`

Check warning on line 1606 in src/read.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

unresolved link to `Component::ParentDir`

Check warning on line 1606 in src/read.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--all-features)

unresolved link to `Component::ParentDir`

Check warning on line 1606 in src/read.rs

View workflow job for this annotation

GitHub Actions / style_and_docs

unresolved link to `Component::ParentDir`
pub fn mangled_name(&self) -> PathBuf {
self.data.file_name_sanitized()
}
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());
}
Loading