aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 16:25:52 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 17:34:46 +0900
commit659e8a4ee130d968ef6bfb22159fb547e366f969 (patch)
treeb23dc0036b90526cfe3f1809b4d2396d9a1118bb /crates
parent652860a48d0ea5db5f9b20ed98ff69a98d32c656 (diff)
downloadphp-shirabe-659e8a4ee130d968ef6bfb22159fb547e366f969.tar.gz
php-shirabe-659e8a4ee130d968ef6bfb22159fb547e366f969.tar.zst
php-shirabe-659e8a4ee130d968ef6bfb22159fb547e366f969.zip
fix(php-shim): fail RecursiveIteratorFileInfo::get_size on a failed stat
This is the type Filesystem::directory_size() actually iterates, and it swallowed a failed stat as 0 the same way. PHP's iterator yields \SplFileInfo there, so raise the same \RuntimeException it would. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-php-shim/src/fs.rs13
-rw-r--r--crates/shirabe/src/util/filesystem.rs2
2 files changed, 10 insertions, 5 deletions
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index 0006020a..26ea1fdf 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -189,10 +189,15 @@ impl RecursiveIteratorFileInfo {
self.path.to_string_lossy().into_owned()
}
- pub fn get_size(&self) -> i64 {
- std::fs::metadata(&self.path)
- .map(|m| m.len() as i64)
- .unwrap_or(0)
+ pub fn get_size(&self) -> anyhow::Result<i64> {
+ match filesize(&self.path) {
+ Some(size) => Ok(size),
+ None => Err(crate::RuntimeException::new(format!(
+ "SplFileInfo::getSize(): stat failed for {}",
+ self.path.display()
+ ))
+ .into()),
+ }
}
fn sub_pathname(&self) -> String {
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 44dddb8c..1a9ab703 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -856,7 +856,7 @@ impl Filesystem {
let mut size: i64 = 0;
for file in &ri {
if file.is_file() {
- size += file.get_size();
+ size += file.get_size()?;
}
}