From 264feb1093d587e5df457fac023852a0e578b22f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 10 Aug 2026 02:59:50 +0900 Subject: fix(php-shim): return an error from fileperms instead of 0 fileperms swallowed metadata errors and reported a mode of 0, which the callers could not tell apart from a real (if implausible) mode: the zip archiver stored entries with no permission bits, and Filesystem::copy chmod-ed the target to 0. It now returns Result so both callers propagate the failure. The switch to u32 also drops the casts around the mode arithmetic and ZipArchive's entry attributes. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-shim/src/zip.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/shirabe-php-shim/src/zip.rs') diff --git a/crates/shirabe-php-shim/src/zip.rs b/crates/shirabe-php-shim/src/zip.rs index f028ffd0..4fab9aad 100644 --- a/crates/shirabe-php-shim/src/zip.rs +++ b/crates/shirabe-php-shim/src/zip.rs @@ -218,7 +218,7 @@ impl ZipArchive { ))) } - pub fn add_empty_dir(&self, local_name: &str, opsys: i64, attr: i64) -> bool { + pub fn add_empty_dir(&self, local_name: &str, opsys: i64, attr: u32) -> bool { let mut state = self.state.borrow_mut(); let ZipState::Writer { writer, .. } = &mut *state else { return false; @@ -233,7 +233,7 @@ impl ZipArchive { filepath: impl AsRef, local_name: &str, opsys: i64, - attr: i64, + attr: u32, ) -> bool { let contents = match std::fs::read(filepath.as_ref()) { Ok(c) => c, @@ -257,14 +257,14 @@ impl ZipArchive { /// keeps only the low 9 mode bits, on top of which the crate restores `S_IFREG` for /// files and `S_IFDIR` for directories; libzip stores `attr` verbatim, so /// setuid/setgid/sticky bits and the remaining file types do not survive. - fn entry_options(opsys: i64, attr: i64) -> SimpleFileOptions { + fn entry_options(opsys: i64, attr: u32) -> SimpleFileOptions { let system = match opsys { Self::OPSYS_UNIX => zip::System::Unix, _ => todo!(), }; SimpleFileOptions::default() .system(system) - .unix_permissions((attr >> 16) as u32) + .unix_permissions(attr >> 16) } pub fn get_status_string(&self) -> String { -- cgit v1.3.1-4-g156e