From c0b743c8d75813003756a72d2fdd110de8368b5f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 20:34:12 +0900 Subject: 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) --- crates/shirabe/src/downloader/download_manager.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'crates/shirabe/src/downloader') 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> 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!( " Now trying to download from {}", @@ -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::().is_some(); let is_irrecoverable = e.downcast_ref::().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); } } -- cgit v1.3.1