From 5488b18fd0387d655192350011f331dfda03ebba Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 20 Jun 2026 19:39:32 +0900 Subject: feat(php-shim): implement is_writable via filesystem metadata Replace the todo!() with a std-only check on the path's permission bits. A TODO notes this approximates PHP's access(2)/W_OK and can diverge for files the current user does not own; to be refined with a syscall crate. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/shirabe-php-shim/src') diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 08fe361..d75c1aa 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -1457,8 +1457,14 @@ pub fn file_exists(_path: &str) -> bool { std::path::Path::new(_path).exists() } +// TODO(phase-c): PHP's is_writable() resolves to access(2) with W_OK, honoring the effective +// user/group and ACLs. This std-only approximation only inspects the permission bits, so it can +// diverge for files the current user does not own. Refine with a syscall (libc/rustix) crate later. pub fn is_writable(_path: &str) -> bool { - todo!() + match std::fs::metadata(_path) { + Ok(meta) => !meta.permissions().readonly(), + Err(_) => false, + } } pub fn unlink(_path: &str) -> bool { -- cgit v1.3.1