Fix folder softlink is not preserved after packing

Signed-off-by: tommady <tommady@users.noreply.github.com>
This commit is contained in:
tommady 2025-07-17 08:38:11 +00:00
parent bbce746666
commit 3858076274
No known key found for this signature in database
GPG Key ID: 175B664929DF2F2F
2 changed files with 6 additions and 6 deletions

View File

@ -141,9 +141,7 @@ where
info(format!("Compressing '{}'", EscapedPathDisplay::new(path)));
}
if path.is_dir() {
builder.append_dir(path, path)?;
} else if path.is_symlink() && !follow_symlinks {
if ((path.is_dir() && path.symlink_metadata()?.is_symlink()) || path.is_symlink()) && !follow_symlinks {
let target_path = path.read_link()?;
let mut header = tar::Header::new_gnu();
@ -155,6 +153,8 @@ where
.detail("Unexpected error while trying to read link")
.detail(format!("Error: {err}."))
})?;
} else if path.is_dir() {
builder.append_dir(path, path)?;
} else {
let mut file = match fs::File::open(path) {
Ok(f) => f,

View File

@ -242,9 +242,7 @@ where
.detail(format!("File at '{path:?}' has a non-UTF-8 name"))
})?;
if metadata.is_dir() {
writer.add_directory(entry_name, options)?;
} else if path.is_symlink() && !follow_symlinks {
if ((path.is_dir() && path.symlink_metadata()?.is_symlink()) || path.is_symlink()) && !follow_symlinks {
let target_path = path.read_link()?;
let target_name = target_path.to_str().ok_or_else(|| {
FinalError::with_title("Zip requires that all directories names are valid UTF-8")
@ -259,6 +257,8 @@ where
let symlink_options = options.unix_permissions(0o120777);
writer.add_symlink(entry_name, target_name, symlink_options)?;
} else if path.is_dir() {
writer.add_directory(entry_name, options)?;
} else {
#[cfg(not(unix))]
let options = if is_executable::is_executable(path) {