From 9b291d454b059977639db26c847af4e835cda0c3 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Jul 2026 18:03:57 +0900 Subject: refactor(downloader): take &self across the downloader hierarchy Concurrent package operations call into the same downloader instances through Rc>; with &mut self methods every call holds a RefMut across its awaits, which panics with 'already mutably borrowed' the moment two operations overlap. This is groundwork for fanning out InstallationManager's download/install loops (same rework HttpDownloader/CurlDownloader already got). - DownloaderInterface/ChangeReportInterface/ArchiveDownloader/ VcsDownloader methods now take &self; as_change_report_interface returns &dyn instead of &mut dyn. - Implementors move their genuinely mutable state behind cells: FileDownloader.additional_cleanup_paths, the archive downloaders' cleanup_executed, ZipDownloader.zip_archive_object, VcsDownloaderBase.has_cleaned_changes, GitDownloader's stash/discard/ cache maps and GitUtil, SvnDownloader.cache_credentials, PerforceDownloader.perforce. FileDownloader.io gains a RefCell layer so get_local_changes can keep PHP's NullIO swap under &self. - ProcessExecutor::execute_async now returns a future that captures everything up front instead of borrowing the executor, and call sites build the future before awaiting, so no borrow on the shared executor is held while a subprocess runs. - Filesystem::remove_directory_async becomes remove_directory_async_via taking the Rc handle: the Filesystem is only borrowed for the sync head/tail, never across the rm subprocess await (sync borrow_mut users like rename/ensure_directory_exists would otherwise collide). - DownloadManager async call sites hold shared borrows only. Co-Authored-By: Claude Fable 5 --- crates/shirabe/tests/downloader/zip_downloader_test.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/shirabe/tests/downloader/zip_downloader_test.rs') diff --git a/crates/shirabe/tests/downloader/zip_downloader_test.rs b/crates/shirabe/tests/downloader/zip_downloader_test.rs index 878c8054..593f3e76 100644 --- a/crates/shirabe/tests/downloader/zip_downloader_test.rs +++ b/crates/shirabe/tests/downloader/zip_downloader_test.rs @@ -155,7 +155,7 @@ fn test_error_messages() { let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( io.clone(), )))); - let mut downloader = ZipDownloader::new( + let downloader = ZipDownloader::new( io, config, http_downloader.clone(), @@ -173,13 +173,13 @@ fn test_error_messages() { let result: anyhow::Result<()> = (|| { let mut loop_ = Loop::new(http_downloader.clone(), None); let promise = Box::pin(async { - DownloaderInterface::download(&mut downloader, package.clone(), &path, None, true) + DownloaderInterface::download(&downloader, package.clone(), &path, None, true) .await .map(|_| ()) }); run(loop_.wait(vec![promise], None))?; run(DownloaderInterface::install( - &mut downloader, + &downloader, package.clone(), &path, true, @@ -198,7 +198,7 @@ fn test_zip_archive_only_failed() { let _tear_down = TearDown::new(set_up.test_dir.path().to_path_buf()); ZipDownloader::__set_has_zip_archive(Some(true)); - let mut downloader = make_downloader(&set_up); + let downloader = make_downloader(&set_up); let zip_archive = ZipArchive::__mock(ZipArchiveMock { open: Ok(()), count: 0, @@ -224,7 +224,7 @@ fn test_zip_archive_extract_only_failed() { let _tear_down = TearDown::new(set_up.test_dir.path().to_path_buf()); ZipDownloader::__set_has_zip_archive(Some(true)); - let mut downloader = make_downloader(&set_up); + let downloader = make_downloader(&set_up); let zip_archive = ZipArchive::__mock(ZipArchiveMock { open: Ok(()), count: 0, @@ -252,7 +252,7 @@ fn test_zip_archive_only_good() { let _tear_down = TearDown::new(set_up.test_dir.path().to_path_buf()); ZipDownloader::__set_has_zip_archive(Some(true)); - let mut downloader = make_downloader(&set_up); + let downloader = make_downloader(&set_up); let zip_archive = ZipArchive::__mock(ZipArchiveMock { open: Ok(()), count: 0, -- cgit v1.3.1