aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/archiver
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-09 07:19:49 +0900
committernsfisis <nsfisis@gmail.com>2026-08-09 07:19:49 +0900
commitae19de8597f41c83983e6e6ca35f31d845f16bd3 (patch)
treec9050af966b680dc9ddda3dbb3fa8180fbae6e4a /crates/shirabe/src/package/archiver
parent6b83e68d7961f150ec15dd59d457d519e0bf8663 (diff)
downloadphp-shirabe-ae19de8597f41c83983e6e6ca35f31d845f16bd3.tar.gz
php-shirabe-ae19de8597f41c83983e6e6ca35f31d845f16bd3.tar.zst
php-shirabe-ae19de8597f41c83983e6e6ca35f31d845f16bd3.zip
feat(archiver): preserve file permissions in zip archives
The shim reported setExternalAttributesName as missing, so ZipArchiver took the branch for libzip below 0.11.2 and every archived entry got the zip crate's default mode. The attributes now travel as arguments to add_file and add_empty_dir, because the crate fixes an entry's external attributes when the entry is started and offers no way to amend one already written. unix_permissions keeps only the low 9 mode bits, on top of which the crate restores S_IFREG and S_IFDIR, so setuid/setgid/sticky bits and other file types are still dropped. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/archiver')
-rw-r--r--crates/shirabe/src/package/archiver/zip_archiver.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/shirabe/src/package/archiver/zip_archiver.rs b/crates/shirabe/src/package/archiver/zip_archiver.rs
index e5bb613d..5604c07d 100644
--- a/crates/shirabe/src/package/archiver/zip_archiver.rs
+++ b/crates/shirabe/src/package/archiver/zip_archiver.rs
@@ -5,9 +5,7 @@ use crate::package::archiver::ArchiverInterface;
use crate::util::Filesystem;
use crate::util::Platform;
use indexmap::IndexMap;
-use shirabe_php_shim::{
- PhpMixed, RuntimeException, ZipArchive, class_exists, fileperms, method_exists, realpath,
-};
+use shirabe_php_shim::{RuntimeException, ZipArchive, class_exists, fileperms, realpath};
use std::path::PathBuf;
#[derive(Debug)]
@@ -71,16 +69,18 @@ impl ArchiverInterface for ZipArchiver {
));
}
+ // Ensure to preserve the permission umasks for the filepath in the archive.
+ let perms = fileperms(&filepath);
+
if filepath.is_dir() {
- zip.add_empty_dir(&relative_path.to_string_lossy());
+ zip.add_empty_dir(
+ &relative_path.to_string_lossy(),
+ ZipArchive::OPSYS_UNIX,
+ perms << 16,
+ );
} else {
- zip.add_file(&filepath, &relative_path.to_string_lossy());
- }
-
- // setExternalAttributesName() is only available with libzip 0.11.2 or above
- if method_exists(&PhpMixed::Null, "setExternalAttributesName") {
- let perms = fileperms(&filepath);
- zip.set_external_attributes_name(
+ zip.add_file(
+ &filepath,
&relative_path.to_string_lossy(),
ZipArchive::OPSYS_UNIX,
perms << 16,