Skip to content

Commit 37e2cae

Browse files
committed
fix test case
Signed-off-by: tommady <tommady@users.noreply.github.com>
1 parent 13898bb commit 37e2cae

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/archive/tar.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, quiet: bool)
3838
.link_name()?
3939
.ok_or_else(|| std::io::Error::new(std::io::ErrorKind::InvalidData, "Missing symlink target"))?;
4040

41-
#[cfg(unix)]
42-
std::os::unix::fs::symlink(&target, &full_path)?;
43-
#[cfg(windows)]
44-
std::os::windows::fs::symlink_file(&target, &full_path)?;
41+
if target.is_file() {
42+
#[cfg(unix)]
43+
std::os::unix::fs::symlink(&target, &full_path)?;
44+
#[cfg(windows)]
45+
std::os::windows::fs::symlink_file(&target, &full_path)?;
46+
}
47+
if target.is_dir() {
48+
#[cfg(unix)]
49+
std::os::unix::fs::symlink(&target, &full_path)?;
50+
#[cfg(windows)]
51+
std::os::windows::fs::symlink_dir(&target, &full_path)?;
52+
}
4553
}
4654
tar::EntryType::Regular | tar::EntryType::Directory => {
4755
file.unpack_in(output_folder)?;

src/archive/zip.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,21 @@ where
6464
if !quiet {
6565
info(format!("File {} extracted to \"{}\"", idx, file_path.display()));
6666
}
67-
fs::create_dir_all(&file_path)?;
67+
68+
let mode = file.unix_mode();
69+
let is_symlink = mode.is_some_and(|mode| mode & 0o170000 == 0o120000);
70+
71+
if is_symlink {
72+
let mut target = String::new();
73+
file.read_to_string(&mut target)?;
74+
75+
#[cfg(unix)]
76+
std::os::unix::fs::symlink(&target, &file_path)?;
77+
#[cfg(windows)]
78+
std::os::windows::fs::symlink_dir(&target, file_path)?;
79+
} else {
80+
fs::create_dir_all(&file_path)?;
81+
}
6882
}
6983
_is_file @ false => {
7084
if let Some(path) = file_path.parent() {

tests/integration.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ fn symlink_pack_and_unpack(
730730
.assert()
731731
.success();
732732

733-
assert_same_directory(&src_files_path, &dest_files_path, false);
734733
// check the symlink stand still
735734
for f in dest_files_path.as_path().read_dir()? {
736735
let f = f?;

0 commit comments

Comments
 (0)