diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-06 20:34:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-06 20:34:12 +0900 |
| commit | c0b743c8d75813003756a72d2fdd110de8368b5f (patch) | |
| tree | 1e010922456fe5ef08c47bf77e0ff427af764b78 | |
| parent | 2061874a76ed9c255027fd0673b478225fa468d5 (diff) | |
| download | php-shirabe-c0b743c8d75813003756a72d2fdd110de8368b5f.tar.gz php-shirabe-c0b743c8d75813003756a72d2fdd110de8368b5f.tar.zst php-shirabe-c0b743c8d75813003756a72d2fdd110de8368b5f.zip | |
refactor(download-manager): set installation source on package handle
Replace the phase-b TODOs in DownloadManager::download with the actual
package.set_installation_source call, enabled by the interior mutability
of PackageInterfaceHandle. Drop the stale recursive-closure comments now
that the loop expresses the PHP $download($retry) flow.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | crates/shirabe/src/downloader/download_manager.rs | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs index e0998e9..af23353 100644 --- a/crates/shirabe/src/downloader/download_manager.rs +++ b/crates/shirabe/src/downloader/download_manager.rs @@ -211,9 +211,7 @@ impl DownloadManager { let mut sources = self.get_available_sources(package.clone(), prev_package.clone())?; - // PHP closure: uses recursive variable $download and captures $sources by reference - // TODO(phase-b): recursive closure with mutable shared state needs Rc<RefCell<>> or similar - let mut retry_state = false; + let mut retry = false; loop { let source = match array_shift(&mut sources) { Some(s) => s, @@ -221,7 +219,7 @@ impl DownloadManager { return Ok(None); } }; - if retry_state { + if retry { self.io.write_error3( &format!( " <warning>Now trying to download from {}</warning>", @@ -231,14 +229,10 @@ impl DownloadManager { io_interface::NORMAL, ); } - // TODO(phase-b): &mut on shared package — PHP mutates by reference - todo!("package.set_installation_source(Some(source.clone()))"); + package.set_installation_source(Some(source.clone())); - let downloader = match self.get_downloader_for_package(package.clone())? { - Some(d) => d, - None => { - return Ok(None); - } + let Some(downloader) = self.get_downloader_for_package(package.clone())? else { + return Ok(None); }; let result = match downloader @@ -248,7 +242,6 @@ impl DownloadManager { { Ok(r) => r, Err(e) => { - // PHP closure handleError: rethrow if not RuntimeException or if IrrecoverableDownloadException let is_runtime = e.downcast_ref::<RuntimeException>().is_some(); let is_irrecoverable = e.downcast_ref::<IrrecoverableDownloadException>().is_some(); @@ -273,7 +266,7 @@ impl DownloadManager { io_interface::NORMAL, ); - retry_state = true; + retry = true; continue; } @@ -281,8 +274,6 @@ impl DownloadManager { } }; - // PHP: $result->then(static fn ($res) => $res, $handleError); - // The rejection handler ($handleError) is already applied via the try/catch (the Err arm above). return Ok(result); } } |
