aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader/gzip_downloader.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-18 18:03:57 +0900
committernsfisis <nsfisis@gmail.com>2026-07-18 18:03:57 +0900
commit9b291d454b059977639db26c847af4e835cda0c3 (patch)
treee54770570a80e67681f1614841156b864452713c /crates/shirabe/src/downloader/gzip_downloader.rs
parentf8e385f7a1bd752d39f4d4f87b0439596839dde9 (diff)
downloadphp-shirabe-9b291d454b059977639db26c847af4e835cda0c3.tar.gz
php-shirabe-9b291d454b059977639db26c847af4e835cda0c3.tar.zst
php-shirabe-9b291d454b059977639db26c847af4e835cda0c3.zip
refactor(downloader): take &self across the downloader hierarchy
Concurrent package operations call into the same downloader instances through Rc<RefCell<dyn DownloaderInterface>>; 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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/downloader/gzip_downloader.rs')
-rw-r--r--crates/shirabe/src/downloader/gzip_downloader.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs
index 4ea2a327..4ea8f3b9 100644
--- a/crates/shirabe/src/downloader/gzip_downloader.rs
+++ b/crates/shirabe/src/downloader/gzip_downloader.rs
@@ -22,7 +22,7 @@ use shirabe_php_shim::{
#[derive(Debug)]
pub struct GzipDownloader {
inner: FileDownloader,
- cleanup_executed: IndexMap<String, bool>,
+ cleanup_executed: std::cell::RefCell<IndexMap<String, bool>>,
}
impl GzipDownloader {
@@ -45,7 +45,7 @@ impl GzipDownloader {
Some(filesystem),
Some(process),
),
- cleanup_executed: IndexMap::new(),
+ cleanup_executed: std::cell::RefCell::new(IndexMap::new()),
}
}
@@ -69,20 +69,12 @@ impl ArchiveDownloader for GzipDownloader {
&self.inner
}
- fn inner_mut(&mut self) -> &mut FileDownloader {
- &mut self.inner
- }
-
- fn cleanup_executed(&self) -> &IndexMap<String, bool> {
+ fn cleanup_executed(&self) -> &std::cell::RefCell<IndexMap<String, bool>> {
&self.cleanup_executed
}
- fn cleanup_executed_mut(&mut self) -> &mut IndexMap<String, bool> {
- &mut self.cleanup_executed
- }
-
async fn extract(
- &mut self,
+ &self,
package: PackageInterfaceHandle,
file: &str,
path: &str,
@@ -149,7 +141,7 @@ impl ArchiveDownloader for GzipDownloader {
impl ChangeReportInterface for GzipDownloader {
fn get_local_changes(
- &mut self,
+ &self,
package: PackageInterfaceHandle,
path: &str,
) -> anyhow::Result<Option<String>> {
@@ -163,14 +155,12 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
self.inner.get_installation_source()
}
- fn as_change_report_interface(
- &mut self,
- ) -> Option<&mut dyn crate::downloader::ChangeReportInterface> {
+ fn as_change_report_interface(&self) -> Option<&dyn crate::downloader::ChangeReportInterface> {
Some(self)
}
async fn download(
- &mut self,
+ &self,
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
@@ -182,7 +172,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
}
async fn prepare(
- &mut self,
+ &self,
r#type: &str,
package: PackageInterfaceHandle,
path: &str,
@@ -192,7 +182,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
}
async fn install(
- &mut self,
+ &self,
package: PackageInterfaceHandle,
path: &str,
output: bool,
@@ -201,7 +191,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
}
async fn update(
- &mut self,
+ &self,
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
@@ -210,7 +200,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
}
async fn remove(
- &mut self,
+ &self,
package: PackageInterfaceHandle,
path: &str,
output: bool,
@@ -219,7 +209,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
}
async fn cleanup(
- &mut self,
+ &self,
r#type: &str,
package: PackageInterfaceHandle,
path: &str,