aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 16:25:50 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 17:34:46 +0900
commit652860a48d0ea5db5f9b20ed98ff69a98d32c656 (patch)
tree91347941e1da603f690ec445e393fd0a47299195
parent1747352a5b4995eee390ba9eba2e77ec2c1e4586 (diff)
downloadphp-shirabe-652860a48d0ea5db5f9b20ed98ff69a98d32c656.tar.gz
php-shirabe-652860a48d0ea5db5f9b20ed98ff69a98d32c656.tar.zst
php-shirabe-652860a48d0ea5db5f9b20ed98ff69a98d32c656.zip
fix(symfony-finder): fail SplFileInfo::get_size on a failed stat
\SplFileInfo::getSize() throws a \RuntimeException when stat fails, and neither Symfony's subclass nor Composer's Filesystem::directorySize() catches it. Returning 0 turned an unreadable file into an empty one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-rw-r--r--Cargo.lock1
-rw-r--r--crates/shirabe-symfony-finder/Cargo.toml1
-rw-r--r--crates/shirabe-symfony-finder/src/spl_file_info.rs14
3 files changed, 12 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3861f168..0dfd1abf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2257,6 +2257,7 @@ dependencies = [
name = "shirabe-symfony-finder"
version = "0.0.1"
dependencies = [
+ "anyhow",
"chrono",
"indexmap",
"regex",
diff --git a/crates/shirabe-symfony-finder/Cargo.toml b/crates/shirabe-symfony-finder/Cargo.toml
index 8088aa23..0823bfaf 100644
--- a/crates/shirabe-symfony-finder/Cargo.toml
+++ b/crates/shirabe-symfony-finder/Cargo.toml
@@ -10,6 +10,7 @@ license.workspace = true
[dependencies]
shirabe-pcre.workspace = true
shirabe-php-shim.workspace = true
+anyhow.workspace = true
chrono.workspace = true
indexmap.workspace = true
regex.workspace = true
diff --git a/crates/shirabe-symfony-finder/src/spl_file_info.rs b/crates/shirabe-symfony-finder/src/spl_file_info.rs
index b719efc5..40bd153a 100644
--- a/crates/shirabe-symfony-finder/src/spl_file_info.rs
+++ b/crates/shirabe-symfony-finder/src/spl_file_info.rs
@@ -76,9 +76,15 @@ impl SplFileInfo {
shirabe_php_shim::realpath(&self.pathname)
}
- pub fn get_size(&self) -> i64 {
- // \SplFileInfo::getSize() returns the file size in bytes (throws on failure).
- // TODO(php-semantics): PHP throws a \RuntimeException on stat failure; this returns 0 instead.
- shirabe_php_shim::filesize(&self.pathname).unwrap_or(0)
+ pub fn get_size(&self) -> anyhow::Result<i64> {
+ // Inherited from \SplFileInfo, whose failure message names the base class even for subclasses.
+ match shirabe_php_shim::filesize(&self.pathname) {
+ Some(size) => Ok(size),
+ None => Err(shirabe_php_shim::RuntimeException::new(format!(
+ "SplFileInfo::getSize(): stat failed for {}",
+ self.pathname
+ ))
+ .into()),
+ }
}
}