diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-23 03:07:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:48:00 +0900 |
| commit | e068a9d644fde6659a88accd55b3f1d0d9d7cf46 (patch) | |
| tree | bb719a70eb8c840957a94a5601df8961055ceb0f /crates/shirabe/src/downloader/file_downloader.rs | |
| parent | 60eb89529c8af2e4477e0bb65ed9e0f2dc7d3dd7 (diff) | |
| download | php-shirabe-e068a9d644fde6659a88accd55b3f1d0d9d7cf46.tar.gz php-shirabe-e068a9d644fde6659a88accd55b3f1d0d9d7cf46.tar.zst php-shirabe-e068a9d644fde6659a88accd55b3f1d0d9d7cf46.zip | |
refactor(promise): rewrite promise bodies to async/await
Mechanically convert promise-returning function bodies to async/await:
resolve() returns the value directly, forwarding calls get .await, and
simple .then chains become await sequences. Also collapse the installer
double-Option (Result<Option<Option<PhpMixed>>> -> Result<Option<PhpMixed>>).
Hard spots that depend on the Loop::wait / job-machine boundary
(accept/reject orchestration, closures capturing &mut self, batch waits)
are left intact and marked with TODO(phase-c-promise) for manual porting.
The crate does not compile yet; traits still need #[async_trait].
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/downloader/file_downloader.rs')
| -rw-r--r-- | crates/shirabe/src/downloader/file_downloader.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs index 0920342..452ce8c 100644 --- a/crates/shirabe/src/downloader/file_downloader.rs +++ b/crates/shirabe/src/downloader/file_downloader.rs @@ -199,6 +199,7 @@ impl DownloaderInterface for FileDownloader { .borrow_mut() .ensure_directory_exists(&dir_of_file)?; + // TODO(phase-c-promise): rewrite the accept/reject/retry promise orchestration as an async loop. // TODO(plugin): inline closures rely on captured $accept/$reject/$urls/$retries. In Rust // we'd need a struct holding shared state — left as a phase-b refactor. let _ = (output, &urls, &mut retries, cache_key_generator, &file_name); @@ -218,7 +219,7 @@ impl DownloaderInterface for FileDownloader { _path: &str, _prev_package: Option<&dyn PackageInterface>, ) -> Result<Option<PhpMixed>> { - Ok(react_promise_resolve(Some(PhpMixed::Null))) + Ok(Some(PhpMixed::Null)) } /// @inheritDoc @@ -273,7 +274,7 @@ impl DownloaderInterface for FileDownloader { } } - Ok(react_promise_resolve(Some(PhpMixed::Null))) + Ok(Some(PhpMixed::Null)) } /// @inheritDoc @@ -333,7 +334,7 @@ impl DownloaderInterface for FileDownloader { } } - Ok(react_promise_resolve(Some(PhpMixed::Null))) + Ok(Some(PhpMixed::Null)) } /// @inheritDoc @@ -349,10 +350,9 @@ impl DownloaderInterface for FileDownloader { self.get_install_operation_appendix(target, path) )); - let _promise = self.remove(initial, path, false)?; - // TODO(phase-b): chain `.then(|| self.install(target, path, false))` - let _ = (initial, target, path); - todo!("phase-b: chain promise.then(|| self.install(target, path, false))") + // PHP: return $this->remove($initial, $path, false)->then(fn () => $this->install($target, $path, false)); + let _ = self.remove(initial, path, false).await?; + self.install(target, path, false).await } /// @inheritDoc @@ -368,11 +368,20 @@ impl DownloaderInterface for FileDownloader { UninstallOperation::format(package, false) )); } - let _promise = self.filesystem.borrow_mut().remove_directory_async(path)?; + let result = self + .filesystem + .borrow_mut() + .remove_directory_async(path) + .await?; + if !result { + return Err(RuntimeException { + message: format!("Could not completely delete {}, aborting.", path), + code: 0, + } + .into()); + } - // TODO(phase-b): chain `.then(|result| if !result { throw RuntimeException })` - let _ = path; - todo!("phase-b: chain promise.then(|result| {{ if !result {{ throw RuntimeException }} }})") + Ok(None) } } @@ -384,6 +393,8 @@ impl ChangeReportInterface for FileDownloader { package: &dyn PackageInterface, path: &str, ) -> Result<Option<String>> { + // TODO(phase-c-promise): get_local_changes drives promises via http_downloader/process wait(); + // converting requires deciding whether ChangeReportInterface::get_local_changes becomes async. Left as-is. // TODO(phase-b): swap self.io to NullIO and restore — needs a take/swap helper let mut null_io = NullIO::new(); |
