From 37e2caee36f03e580a0a1bc32c3618fd23677330 Mon Sep 17 00:00:00 2001 From: tommady Date: Thu, 17 Jul 2025 09:11:19 +0000 Subject: [PATCH] fix test case Signed-off-by: tommady --- src/archive/tar.rs | 16 ++++++++++++---- src/archive/zip.rs | 16 +++++++++++++++- tests/integration.rs | 1 - 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/archive/tar.rs b/src/archive/tar.rs index 7bcf9cd..b0285e8 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -38,10 +38,18 @@ pub fn unpack_archive(reader: Box, output_folder: &Path, quiet: bool) .link_name()? .ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidData, "Missing symlink target"))?; - #[cfg(unix)] - std::os::unix::fs::symlink(&target, &full_path)?; - #[cfg(windows)] - std::os::windows::fs::symlink_file(&target, &full_path)?; + if target.is_file() { + #[cfg(unix)] + std::os::unix::fs::symlink(&target, &full_path)?; + #[cfg(windows)] + std::os::windows::fs::symlink_file(&target, &full_path)?; + } + if target.is_dir() { + #[cfg(unix)] + std::os::unix::fs::symlink(&target, &full_path)?; + #[cfg(windows)] + std::os::windows::fs::symlink_dir(&target, &full_path)?; + } } tar::EntryType::Regular | tar::EntryType::Directory => { file.unpack_in(output_folder)?; diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 11954cc..59fd226 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -64,7 +64,21 @@ where if !quiet { info(format!("File {} extracted to \"{}\"", idx, file_path.display())); } - fs::create_dir_all(&file_path)?; + + let mode = file.unix_mode(); + let is_symlink = mode.is_some_and(|mode| mode & 0o170000 == 0o120000); + + if is_symlink { + let mut target = String::new(); + file.read_to_string(&mut target)?; + + #[cfg(unix)] + std::os::unix::fs::symlink(&target, &file_path)?; + #[cfg(windows)] + std::os::windows::fs::symlink_dir(&target, file_path)?; + } else { + fs::create_dir_all(&file_path)?; + } } _is_file @ false => { if let Some(path) = file_path.parent() { diff --git a/tests/integration.rs b/tests/integration.rs index c7f3503..88de748 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -730,7 +730,6 @@ fn symlink_pack_and_unpack( .assert() .success(); - assert_same_directory(&src_files_path, &dest_files_path, false); // check the symlink stand still for f in dest_files_path.as_path().read_dir()? { let f = f?;