From bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 23 May 2026 15:45:33 +0900 Subject: refactor(promise): drop \React\Promise Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/shirabe/src/util/filesystem.rs | 55 ++++++++++++----------------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'crates/shirabe/src/util/filesystem.rs') diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 1bf4673..73f21d6 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -149,43 +149,26 @@ impl Filesystem { vec!["rm".to_string(), "-rf".to_string(), directory.to_string()] }; - // TODO(phase-c-promise): execute_async is now async fn -> Result; the .then_boxed continuation that - // inspects the process result and flattens into a recursive removeDirectoryPhp fallback needs job-machine - // boundary design before it can become a flat await chain. - let promise = self.get_process().execute_async( - PhpMixed::List( - cmd.iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) - .collect(), - ), - (), - )?; - - let directory_owned = directory.to_string(); - // TODO(plugin): closure capture of $this in PHP — port wires the same logic via a callback handle. - Ok(promise.then_boxed( - Some(Box::new( - move |process: PhpMixed| -> Box { - // clear stat cache because external processes aren't tracked by the php stat cache - clearstatcache2(false, ""); - - // TODO(phase-b): ArrayObject has no call_method; PHP-side calls $process->isSuccessful(). - let is_successful = matches!(process, PhpMixed::Bool(true)); - if is_successful && !is_dir(&directory_owned) { - return shirabe_external_packages::react::promise::resolve(Some( - PhpMixed::Bool(true), - )); - } + let process = self + .get_process() + .execute_async( + PhpMixed::List( + cmd.iter() + .map(|s| Box::new(PhpMixed::String(s.clone()))) + .collect(), + ), + (), + ) + .await?; - // PHP: \React\Promise\resolve($this->removeDirectoryPhp($directory)) - // The recursive PHP call doesn't have a clean async equivalent; we resort to a sync call. - let mut fs = Filesystem::new(None); - let res = fs.remove_directory_php(&directory_owned).unwrap_or(false); - shirabe_external_packages::react::promise::resolve(Some(PhpMixed::Bool(res))) - }, - )), - None, - )) + // clear stat cache because external processes aren't tracked by the php stat cache + clearstatcache2(false, ""); + + if process.is_successful() && !is_dir(directory) { + return Ok(true); + } + + self.remove_directory_php(directory) } /// Returns null when no edge case was hit. Otherwise a bool whether removal was successful -- cgit v1.3.1