diff --git a/src/archive/tar.rs b/src/archive/tar.rs index cc80b95..7bcf9cd 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -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, diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 28546a1..11954cc 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -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) {