From 971824aa15334fd12d08ae0f441f6bf6079344c3 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 7 Jun 2026 10:33:53 +0900 Subject: feat(shirabe): resolve phase-b TODOs with shared ownership Replace TODO(phase-b) placeholders (todo!() and commented-out code) with real implementations: - Share JsonFile via Rc> so JsonConfigSource and the owning command can hold the same instance (base_config_command, config_command, repository_command, require_command, create_project, remove_command, factory) - Change InstallerInterface methods (is_installed, download, prepare, cleanup, get_install_path) to &mut self so initialize_vendor_dir can run, propagated to all installer implementations - Pass io/config/filesystem/process by clone instead of moving or stubbing (auth_helper, svn_driver, curl_downloader, library_installer) - Make TransportException Clone and store it by value in VcsRepository - Clone operations in Transaction sort, root_aliases/temporary_constraints in RepositorySet::create_pool, and share CompletePackage via handle in PlatformRepository - Wire up set_option, set_requires/set_dev_requires, installation manager setters, BumpCommand::set_composer, and clean_backups/set_local_phar --- crates/shirabe/src/command/base_config_command.rs | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'crates/shirabe/src/command/base_config_command.rs') diff --git a/crates/shirabe/src/command/base_config_command.rs b/crates/shirabe/src/command/base_config_command.rs index 3aed839..d681870 100644 --- a/crates/shirabe/src/command/base_config_command.rs +++ b/crates/shirabe/src/command/base_config_command.rs @@ -15,9 +15,8 @@ use shirabe_php_shim::{PhpMixed, chmod, touch}; pub trait BaseConfigCommand: BaseCommand { fn config(&self) -> Option<&std::rc::Rc>>; fn config_mut(&mut self) -> &mut Option>>; - fn config_file(&self) -> Option<&JsonFile>; - fn config_file_mut(&mut self) -> Option<&mut JsonFile>; - fn set_config_file(&mut self, file: Option); + fn config_file(&self) -> Option<&std::rc::Rc>>; + fn set_config_file(&mut self, file: Option>>); fn config_source(&self) -> Option<&JsonConfigSource>; fn config_source_mut(&mut self) -> Option<&mut JsonConfigSource>; fn set_config_source(&mut self, source: Option); @@ -40,8 +39,7 @@ pub trait BaseConfigCommand: BaseCommand { return Err(anyhow::anyhow!("--file and --global can not be combined")); } - // TODO(phase-b): clone_box to release the &mut self borrow held by get_io. - let io = self.get_io().clone(); + let io = self.get_io(); *self.config_mut() = Some(std::rc::Rc::new(std::cell::RefCell::new( Factory::create_config(Some(io.clone()), None)?, ))); @@ -68,14 +66,13 @@ pub trait BaseConfigCommand: BaseCommand { { std::fs::write(&config_file, "{\n}\n")?; } - self.set_config_file(Some(JsonFile::new( + let config_file_jf = std::rc::Rc::new(std::cell::RefCell::new(JsonFile::new( config_file.clone(), None, Some(io.clone()), )?)); - // TODO(phase-b): JsonConfigSource::new takes owned JsonFile, but PHP shares the same - // instance with $this->configFile. Needs Rc> refactor on both sides. - self.set_config_source(None); + self.set_config_file(Some(config_file_jf.clone())); + self.set_config_source(Some(JsonConfigSource::new(config_file_jf, false))); // Initialize the global file if it's not there, ignoring any warnings or notices if input @@ -83,13 +80,13 @@ pub trait BaseConfigCommand: BaseCommand { .get_option("global") .as_bool() .unwrap_or(false) - && !self.config_file().as_ref().unwrap().exists() + && !self.config_file().unwrap().borrow().exists() { - let path = self.config_file().as_ref().unwrap().get_path().to_string(); + let path = self.config_file().unwrap().borrow().get_path().to_string(); touch(&path); - self.config_file_mut() - .as_mut() + self.config_file() .unwrap() + .borrow() .write(PhpMixed::Array({ let mut m = IndexMap::new(); m.insert( @@ -104,7 +101,7 @@ pub trait BaseConfigCommand: BaseCommand { }); } - if !self.config_file().as_ref().unwrap().exists() { + if !self.config_file().unwrap().borrow().exists() { return Err(anyhow::anyhow!( "File \"{}\" cannot be found in the current directory", config_file -- cgit v1.3.1