diff options
Diffstat (limited to 'crates/shirabe/src/repository')
17 files changed, 113 insertions, 72 deletions
diff --git a/crates/shirabe/src/repository/artifact_repository.rs b/crates/shirabe/src/repository/artifact_repository.rs index eff8fef..1509de3 100644 --- a/crates/shirabe/src/repository/artifact_repository.rs +++ b/crates/shirabe/src/repository/artifact_repository.rs @@ -9,6 +9,7 @@ use shirabe_php_shim::{ }; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::package::BasePackage; use crate::package::loader::ArrayLoader; @@ -24,7 +25,7 @@ pub struct ArtifactRepository { pub(crate) loader: Box<dyn LoaderInterface>, pub(crate) lookup: String, pub(crate) repo_config: IndexMap<String, PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, } impl std::fmt::Debug for ArtifactRepository { @@ -39,7 +40,7 @@ impl std::fmt::Debug for ArtifactRepository { impl ArtifactRepository { pub fn new( repo_config: IndexMap<String, PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, ) -> anyhow::Result<Self> { if !extension_loaded("zip") { return Err(RuntimeException { diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 5c16f8e..d055e59 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -21,6 +21,7 @@ use crate::config::Config; use crate::downloader::TransportException; use crate::event_dispatcher::EventDispatcher; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::package::BasePackageHandle; use crate::package::PackageInterface; @@ -84,7 +85,7 @@ pub struct ComposerRepository { url: String, /// non-empty-string base_url: String, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, r#loop: std::rc::Rc<std::cell::RefCell<Loop>>, pub(crate) cache: Cache, @@ -141,7 +142,7 @@ impl ConfigurableRepositoryInterface for ComposerRepository { impl ComposerRepository { pub fn new( mut repo_config: IndexMap<String, PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: &Config, http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, @@ -258,10 +259,11 @@ impl ComposerRepository { let base_url = base_url_trimmed.trim_end_matches('/').to_string(); assert!(!base_url.is_empty()); - // TODO(phase-b): Cache::new expects Box<dyn IOInterface> but io is also stored in self.io; + // TODO(phase-b): Cache::new expects std::rc::Rc<std::cell::RefCell<dyn IOInterface>> but io is also stored in self.io; // need shared ownership (Rc) for IOInterface. Using todo!() placeholder. - let cache: Cache = - todo!("Cache::new requires Box<dyn IOInterface> but io is also moved into self.io"); + let cache: Cache = todo!( + "Cache::new requires std::rc::Rc<std::cell::RefCell<dyn IOInterface>> but io is also moved into self.io" + ); let version_parser = VersionParser::new(); let loader = ArrayLoader::new(Some(version_parser.clone()), true); @@ -2930,7 +2932,7 @@ impl ComposerRepository { .as_array() .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) .unwrap_or_default(); - HttpDownloader::output_warnings(&*self.io, &self.url, &data_local); + HttpDownloader::output_warnings(&*self.io.borrow(), &self.url, &data_local); if let Some(ck) = cache_key_owned.as_ref() { if !ck.is_empty() && !self.cache.is_read_only() { @@ -3127,7 +3129,7 @@ impl ComposerRepository { .as_array() .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) .unwrap_or_default(); - HttpDownloader::output_warnings(&*self.io, &self.url, &data); + HttpDownloader::output_warnings(&*self.io.borrow(), &self.url, &data); let last_modified_date = response.get_header("last-modified"); response.collect(); @@ -3305,7 +3307,7 @@ impl ComposerRepository { .as_array() .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) .unwrap_or_default(); - HttpDownloader::output_warnings(self.io.as_ref(), &self.url, &data); + HttpDownloader::output_warnings(&*self.io.borrow(), &self.url, &data); let last_modified_date = response.get_header("last-modified"); response.collect(); diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs index 8d9965e..51acff0 100644 --- a/crates/shirabe/src/repository/path_repository.rs +++ b/crates/shirabe/src/repository/path_repository.rs @@ -44,7 +44,7 @@ impl ConfigurableRepositoryInterface for PathRepository { impl PathRepository { pub fn new( repo_config: IndexMap<String, PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: Option<std::rc::Rc<std::cell::RefCell<HttpDownloader>>>, dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, @@ -67,14 +67,14 @@ impl PathRepository { let url = Platform::expand_path(&url_str); let process = process.unwrap_or_else(|| { std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( - io.clone_box(), + io.clone(), )))) }); let version_guesser = VersionGuesser::new( config, process.clone(), VersionParser::new(), - Some(io.clone_box()), + Some(io.clone()), ); let mut options = repo_config .get("options") diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs index 0f2e6b2..908704c 100644 --- a/crates/shirabe/src/repository/repository_factory.rs +++ b/crates/shirabe/src/repository/repository_factory.rs @@ -21,7 +21,7 @@ pub struct RepositoryFactory; impl RepositoryFactory { pub fn config_from_string( - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: &std::rc::Rc<std::cell::RefCell<Config>>, repository: &str, allow_filesystem: bool, @@ -42,9 +42,9 @@ impl RepositoryFactory { let mut json = JsonFile::new( repository.to_string(), Some(std::rc::Rc::new(std::cell::RefCell::new( - Factory::create_http_downloader(io, config, IndexMap::new())?, + Factory::create_http_downloader(io.clone(), config, IndexMap::new())?, ))), - Some(io.clone_box()), + Some(io.clone()), )?; let data = json.read()?; let has_packages = data.get("packages").map_or(false, |v| !v.is_null()); @@ -97,18 +97,19 @@ impl RepositoryFactory { } pub fn from_string( - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: &std::rc::Rc<std::cell::RefCell<Config>>, repository: &str, allow_filesystem: bool, rm: Option<&mut RepositoryManager>, ) -> anyhow::Result<Box<dyn RepositoryInterface>> { - let repo_config = Self::config_from_string(io, config, repository, allow_filesystem)?; + let repo_config = + Self::config_from_string(io.clone(), config, repository, allow_filesystem)?; Self::create_repo(io, config, repo_config, rm) } pub fn create_repo( - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: &std::rc::Rc<std::cell::RefCell<Config>>, repo_config: IndexMap<String, PhpMixed>, rm: Option<&mut RepositoryManager>, @@ -141,7 +142,7 @@ impl RepositoryFactory { } pub fn default_repos( - io: Option<&dyn IOInterface>, + io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>, config: Option<std::rc::Rc<std::cell::RefCell<Config>>>, rm: Option<&mut RepositoryManager>, ) -> anyhow::Result<IndexMap<String, Box<dyn RepositoryInterface>>> { @@ -149,7 +150,7 @@ impl RepositoryFactory { Some(c) => c, None => std::rc::Rc::new(std::cell::RefCell::new(Factory::create_config(None, None)?)), }; - if let Some(_io) = io { + if let Some(_io) = &io { // TODO(phase-b): IOInterface::load_configuration requires &mut self, but this // function takes &dyn IOInterface. Wider refactor needed; skip for now. } @@ -164,7 +165,7 @@ impl RepositoryFactory { code: 0, })?; owned_rm = Self::manager( - io, + io.clone(), &config, Some(std::rc::Rc::new(std::cell::RefCell::new( Factory::create_http_downloader(io, &config, IndexMap::new())?, @@ -181,7 +182,7 @@ impl RepositoryFactory { } pub fn manager( - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: &std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: Option<std::rc::Rc<std::cell::RefCell<HttpDownloader>>>, event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, @@ -190,7 +191,7 @@ impl RepositoryFactory { let http_downloader = match http_downloader { Some(h) => h, None => std::rc::Rc::new(std::cell::RefCell::new(Factory::create_http_downloader( - io, + io.clone(), config, IndexMap::new(), )?)), @@ -198,7 +199,7 @@ impl RepositoryFactory { let process = match process { Some(p) => p, None => { - let mut p = ProcessExecutor::new(io); + let mut p = ProcessExecutor::new(Some(io.clone())); p.enable_async(); std::rc::Rc::new(std::cell::RefCell::new(p)) } @@ -231,14 +232,15 @@ impl RepositoryFactory { } pub fn default_repos_with_default_manager( - io: &mut dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, ) -> anyhow::Result<IndexMap<String, Box<dyn RepositoryInterface>>> { let config = std::rc::Rc::new(std::cell::RefCell::new(Factory::create_config( - Some(io), + Some(io.clone()), None, )?)); - let mut manager = Self::manager(io, &config, None, None, None)?; - io.load_configuration(&mut *config.borrow_mut())?; + let mut manager = Self::manager(io.clone(), &config, None, None, None)?; + io.borrow_mut() + .load_configuration(&mut *config.borrow_mut())?; Self::default_repos(Some(io), Some(config), Some(&mut manager)) } diff --git a/crates/shirabe/src/repository/repository_manager.rs b/crates/shirabe/src/repository/repository_manager.rs index f432d6e..72c3643 100644 --- a/crates/shirabe/src/repository/repository_manager.rs +++ b/crates/shirabe/src/repository/repository_manager.rs @@ -7,6 +7,7 @@ use shirabe_semver::constraint::AnyConstraint; use crate::config::Config; use crate::event_dispatcher::EventDispatcher; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::package::PackageInterfaceHandle; use crate::repository::FilterRepository; use crate::repository::InstalledRepositoryInterface; @@ -19,7 +20,7 @@ pub struct RepositoryManager { local_repository: Option<Box<dyn InstalledRepositoryInterface>>, repositories: Vec<Box<dyn RepositoryInterface>>, repository_classes: IndexMap<String, String>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, @@ -28,19 +29,22 @@ pub struct RepositoryManager { impl RepositoryManager { pub fn new( - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, process: Option<std::rc::Rc<std::cell::RefCell<ProcessExecutor>>>, ) -> Self { - let process = process - .unwrap_or_else(|| std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(io)))); + let process = process.unwrap_or_else(|| { + std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( + io.clone(), + )))) + }); Self { local_repository: None, repositories: vec![], repository_classes: IndexMap::new(), - io: io.clone_box(), + io, config, http_downloader, event_dispatcher, diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs index 1c9c4a3..3a81eda 100644 --- a/crates/shirabe/src/repository/repository_set.rs +++ b/crates/shirabe/src/repository/repository_set.rs @@ -456,7 +456,7 @@ impl RepositorySet { pub fn create_pool( &mut self, request: Request, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, pool_optimizer: Option<PoolOptimizer>, ignored_types: Vec<String>, @@ -609,7 +609,7 @@ impl RepositorySet { self.create_pool( request, - Box::new(NullIO::new()), + std::rc::Rc::new(std::cell::RefCell::new(NullIO::new())), None, None, vec![], diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 72fd6af..ccd0c16 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -12,6 +12,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::downloader::TransportException; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::repository::vcs::GitDriver; use crate::repository::vcs::VcsDriverBase; @@ -51,7 +52,7 @@ impl ForgejoDriver { self.forgejo_url = Some(forgejo_url); self.inner.cache = Some(Cache::new( - self.inner.io.clone_box(), + self.inner.io.clone(), &cache_dir, None, None, diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 4982d17..207a138 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -9,6 +9,7 @@ use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_file, is_ use crate::cache::Cache; use crate::config::Config; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::repository::vcs::VcsDriverBase; use crate::util::Filesystem; use crate::util::ProcessExecutor; @@ -31,7 +32,7 @@ impl FossilDriver { // Ensure we are allowed to use this URL by config. self.inner.config.borrow_mut().prohibit_url_by_config( &self.inner.url, - Some(&*self.inner.io), + Some(&*self.inner.io.borrow()), &indexmap::IndexMap::new(), )?; @@ -289,7 +290,12 @@ impl FossilDriver { Ok(self.branches.clone().unwrap_or_default()) } - pub fn supports(io: &dyn IOInterface, config: &Config, url: &str, deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: &Config, + url: &str, + deep: bool, + ) -> bool { if Preg::is_match( r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i", url, @@ -310,7 +316,7 @@ impl FossilDriver { return false; } - let mut process = ProcessExecutor::new(io); + let mut process = ProcessExecutor::new(Some(io)); let mut output = String::new(); if process.execute_args( &["fossil", "info"].map(|s| s.to_string()).to_vec(), diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index 19f0246..53e49fc 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -15,6 +15,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::downloader::TransportException; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::repository::vcs::GitDriver; use crate::repository::vcs::VcsDriverBase; @@ -80,7 +81,7 @@ impl GitBitbucketDriver { self.repository = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); self.inner.origin_url = "bitbucket.org".to_string(); self.inner.cache = Some(Cache::new( - self.inner.io.clone_box(), + self.inner.io.clone(), &implode( "/", &[ @@ -693,7 +694,7 @@ impl GitBitbucketDriver { Err(e) => { // TODO(phase-b): only handle TransportException let mut bitbucket_util = Bitbucket::new( - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), Some(self.inner.process.clone()), Some(self.inner.http_downloader.clone()), diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 69b16b6..665e2fb 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -13,6 +13,7 @@ use shirabe_php_shim::{ use crate::cache::Cache; use crate::config::Config; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::repository::vcs::VcsDriverBase; use crate::util::Filesystem; use crate::util::Git as GitUtil; @@ -31,7 +32,7 @@ pub struct GitDriver { impl GitDriver { pub fn new( repo_config: IndexMap<String, shirabe_php_shim::PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: std::rc::Rc<std::cell::RefCell<crate::util::HttpDownloader>>, process: std::rc::Rc<std::cell::RefCell<ProcessExecutor>>, @@ -117,7 +118,7 @@ impl GitDriver { } let mut git_util = GitUtil::new( - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), self.inner.process.clone(), std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None))), @@ -154,7 +155,7 @@ impl GitDriver { .unwrap_or("") .to_string(); self.inner.cache = Some(Cache::new( - self.inner.io.clone_box(), + self.inner.io.clone(), &format!( "{}/{}", cache_repo_dir, @@ -183,7 +184,7 @@ impl GitDriver { self.root_identifier = Some("master".to_string()); let mut git_util = GitUtil::new( - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), self.inner.process.clone(), std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None))), @@ -399,7 +400,7 @@ impl GitDriver { } pub fn supports( - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, _config: &Config, url: &str, deep: bool, @@ -419,7 +420,9 @@ impl GitDriver { return Ok(false); } - let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(io))); + let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( + io.clone(), + )))); let mut output = String::new(); if process.borrow_mut().execute_args( &["git".to_string(), "tag".to_string()], @@ -432,7 +435,7 @@ impl GitDriver { GitUtil::check_for_repo_ownership_error( &process.borrow().get_error_output(), &url, - Some(io), + Some(io.clone()), )?; } @@ -440,7 +443,9 @@ impl GitDriver { return Ok(false); } - let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(io))); + let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( + io.clone(), + )))); // TODO(phase-b): supports() takes &Config; GitUtil now needs Rc<RefCell<Config>>. // Skipping clean Rc construction since we cannot reconstruct one from a borrowed &Config. let _ = _config; @@ -449,7 +454,7 @@ impl GitDriver { )); #[allow(unreachable_code)] let mut git_util = GitUtil::new( - io.clone_box(), + io.clone(), todo!(), process.clone(), std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None))), diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 6c8d495..5f8266c 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -15,6 +15,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::downloader::TransportException; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::repository::vcs::GitDriver; use crate::repository::vcs::VcsDriverBase; @@ -88,7 +89,7 @@ impl GitHubDriver { self.inner.origin_url = "github.com".to_string(); } self.inner.cache = Some(Cache::new( - self.inner.io.clone_box(), + self.inner.io.clone(), &format!( "{}/{}/{}/{}", self.inner @@ -1015,7 +1016,7 @@ impl GitHubDriver { Ok(r) => Ok(r), Err(e) => { let mut git_hub_util = GitHub::new( - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), Some(self.inner.process.clone()), Some(self.inner.http_downloader.clone()), @@ -1294,7 +1295,7 @@ impl GitHubDriver { repo_config.insert("url".to_string(), PhpMixed::String(url.to_string())); let mut git_driver = GitDriver::new( repo_config, - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), self.inner.http_downloader.clone(), self.inner.process.clone(), diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 8a24b7d..e31eb67 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -15,6 +15,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::downloader::TransportException; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::repository::vcs::GitDriver; use crate::repository::vcs::VcsDriverBase; @@ -183,7 +184,7 @@ impl GitLabDriver { .unwrap_or_default(); self.inner.cache = Some(Cache::new( - self.inner.io.clone_box(), + self.inner.io.clone(), &format!( "{}/{}/{}/{}", self.inner @@ -768,7 +769,7 @@ impl GitLabDriver { repo_config.insert("url".to_string(), PhpMixed::String(url.to_string())); let mut git_driver = GitDriver::new( repo_config, - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), self.inner.http_downloader.clone(), self.inner.process.clone(), @@ -885,7 +886,7 @@ impl GitLabDriver { } Err(e) => { let mut git_lab_util = GitLab::new( - self.inner.io.clone_box(), + self.inner.io.clone(), self.inner.config.clone(), Some(self.inner.process.clone()), Some(self.inner.http_downloader.clone()), diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 8f40d2a..ab3bd0c 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -3,6 +3,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::io::io_interface; use crate::repository::vcs::VcsDriverBase; use crate::util::Filesystem; @@ -61,12 +62,12 @@ impl HgDriver { self.inner.config.borrow_mut().prohibit_url_by_config( &self.inner.url, - Some(&*self.inner.io), + Some(&*self.inner.io.borrow()), &indexmap::IndexMap::new(), )?; let hg_utils = HgUtils::new( - &*self.inner.io, + self.inner.io.clone(), &*self.inner.config.borrow(), &self.inner.process, ); @@ -308,7 +309,12 @@ impl HgDriver { Ok(self.branches.clone().unwrap_or_default()) } - pub fn supports(io: &dyn IOInterface, config: &Config, url: &str, deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: &Config, + url: &str, + deep: bool, + ) -> bool { if Preg::is_match( r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i", url, @@ -324,7 +330,7 @@ impl HgDriver { return false; } - let mut process = crate::util::ProcessExecutor::new(io); + let mut process = crate::util::ProcessExecutor::new(Some(io.clone())); let mut output = String::new(); if process.execute_args( &["hg", "summary"].map(|s| s.to_string()).to_vec(), @@ -340,7 +346,7 @@ impl HgDriver { return false; } - let mut process = crate::util::ProcessExecutor::new(io); + let mut process = crate::util::ProcessExecutor::new(Some(io)); let mut ignored = String::new(); let exit = process.execute_args( &["hg", "identify", "--", url] diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs index 35da517..03948b3 100644 --- a/crates/shirabe/src/repository/vcs/perforce_driver.rs +++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs @@ -77,7 +77,7 @@ impl PerforceDriver { self.inner.url.clone(), repo_dir, self.inner.process.clone(), - self.inner.io.clone_box(), + self.inner.io.clone(), )); Ok(()) @@ -167,9 +167,14 @@ impl PerforceDriver { .into()) } - pub fn supports(io: &dyn IOInterface, _config: &Config, url: &str, deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + _config: &Config, + url: &str, + deep: bool, + ) -> bool { if deep || Preg::is_match(r"#\b(perforce|p4)\b#i", url).unwrap_or(false) { - return Perforce::check_server_exists(url, &mut ProcessExecutor::new(io)); + return Perforce::check_server_exists(url, &mut ProcessExecutor::new(Some(io))); } false } diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index a6ca9c1..a793340 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -468,7 +468,12 @@ impl SvnDriver { self.branches.as_ref().unwrap() } - pub fn supports(io: &dyn IOInterface, _config: &Config, url: &str, deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + _config: &Config, + url: &str, + deep: bool, + ) -> bool { let url = Self::normalize_url(url); if Preg::is_match(r"#(^svn://|^svn\+ssh://|svn\.)#i", &url).unwrap_or(false) { return true; @@ -479,7 +484,7 @@ impl SvnDriver { return false; } - let mut process = ProcessExecutor::new(io); + let mut process = ProcessExecutor::new(Some(io)); let mut ignored_output = String::new(); let exit = process.execute_args( &[ diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index 71476b9..15dd722 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -23,7 +23,7 @@ pub struct VcsDriverBase { pub url: String, pub origin_url: String, pub repo_config: IndexMap<String, PhpMixed>, - pub io: Box<dyn IOInterface>, + pub io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, pub config: std::rc::Rc<std::cell::RefCell<Config>>, pub process: std::rc::Rc<std::cell::RefCell<ProcessExecutor>>, pub http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, @@ -34,7 +34,7 @@ pub struct VcsDriverBase { impl VcsDriverBase { pub fn new( repo_config: IndexMap<String, PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, process: std::rc::Rc<std::cell::RefCell<ProcessExecutor>>, diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index a256fb8..804ba51 100644 --- a/crates/shirabe/src/repository/vcs_repository.rs +++ b/crates/shirabe/src/repository/vcs_repository.rs @@ -15,6 +15,7 @@ use crate::config::Config; use crate::downloader::TransportException; use crate::event_dispatcher::EventDispatcher; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::package::loader::ArrayLoader; use crate::package::loader::InvalidPackageException; use crate::package::loader::LoaderInterface; @@ -43,7 +44,7 @@ pub struct VcsRepository { /// @var bool pub(crate) is_very_verbose: bool, /// @var IOInterface - pub(crate) io: Box<dyn IOInterface>, + pub(crate) io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, /// @var Config pub(crate) config: std::rc::Rc<std::cell::RefCell<Config>>, /// @var VersionParser @@ -87,7 +88,7 @@ impl VcsRepository { /// @param array<string, class-string<VcsDriverInterface>>|null $drivers pub fn new( mut repo_config: IndexMap<String, PhpMixed>, - io: Box<dyn IOInterface>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, @@ -158,7 +159,7 @@ impl VcsRepository { let is_very_verbose = io.is_very_verbose(); let process_executor = process.unwrap_or_else(|| { std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( - io.clone_box(), + io.clone(), )))) }); |
