From 01ff6617a7431537a8d7cfdc4b88aa6fca128d5d Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Thu, 26 Dec 2024 08:50:02 +0800 Subject: [PATCH 1/5] bump up version to 0.4.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- rim_gui/src-tauri/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fded299e..462452b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3031,7 +3031,7 @@ dependencies = [ [[package]] name = "rim" -version = "0.3.1" +version = "0.4.0" dependencies = [ "anyhow", "cc", @@ -3066,7 +3066,7 @@ dependencies = [ [[package]] name = "rim-gui" -version = "0.3.1" +version = "0.4.0" dependencies = [ "anyhow", "fern", diff --git a/Cargo.toml b/Cargo.toml index 678bc201..54939602 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rim" -version = "0.3.1" +version = "0.4.0" edition = "2021" description = "An interactive Rust installation manager" rust-version = "1.73.0" # Minimal required version to use `zip` diff --git a/rim_gui/src-tauri/Cargo.toml b/rim_gui/src-tauri/Cargo.toml index 5bb5ff35..1e340346 100644 --- a/rim_gui/src-tauri/Cargo.toml +++ b/rim_gui/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rim-gui" -version = "0.3.1" +version = "0.4.0" description = "An interactive Rust installation manager" authors = ["you"] edition = "2021" From 6bda94c6c8ba93267219c8a01a422e841f90240e Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Thu, 26 Dec 2024 10:36:31 +0800 Subject: [PATCH 2/5] fixed an error where the `InstallRecord` cannot be loaded, thus failing installation --- src/core/install.rs | 42 ++++++++++++++++++++++------------ src/core/parser/fingerprint.rs | 5 +--- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/core/install.rs b/src/core/install.rs index fb76b7b8..948c0dec 100644 --- a/src/core/install.rs +++ b/src/core/install.rs @@ -74,7 +74,7 @@ pub struct InstallConfiguration<'a> { pub rustup_update_root: Url, /// Indicates whether `cargo` was already installed, useful when installing third-party tools. pub cargo_is_installed: bool, - install_record: InstallationRecord, + install_record: Option, pub(crate) progress_indicator: Option>, manifest: &'a ToolsetManifest, insecure: bool, @@ -90,7 +90,7 @@ impl<'a> InstallConfiguration<'a> { pub fn new(install_dir: &'a Path, manifest: &'a ToolsetManifest) -> Result { Ok(Self { install_dir: install_dir.to_path_buf(), - install_record: InstallationRecord::load(install_dir)?, + install_record: None, cargo_registry: None, rustup_dist_server: default_rustup_dist_server().clone(), rustup_update_root: default_rustup_update_root().clone(), @@ -103,14 +103,15 @@ impl<'a> InstallConfiguration<'a> { /// Creating install diretory and other preperations related to filesystem. /// /// This is suitable for first-time installation. - pub fn setup(&self) -> Result<()> { + pub fn setup(&mut self) -> Result<()> { let install_dir = &self.install_dir; let manifest = self.manifest; info!("{}", t!("install_init", dir = install_dir.display())); - // Create a new folder to hold installation - utils::ensure_dir(install_dir)?; + // Create a new folder to hold installation (`InstallationRecord::load` ensures + // its parent directory) + self.install_record = Some(InstallationRecord::load(install_dir)?); // Create a copy of the manifest which is later used for component management. let manifest_out_path = install_dir.join(ToolsetManifest::FILENAME); @@ -137,6 +138,15 @@ impl<'a> InstallConfiguration<'a> { Ok(()) } + fn get_install_record_mut_unchecked(&mut self) -> &mut InstallationRecord { + self.install_record.as_mut().unwrap_or_else(|| { + panic!( + "internal error: attempt to get installation record before it was initialized \ + make sure to call `setup` after creating a new `InstallConfiguration`" + ) + }) + } + pub fn install(mut self, components: Vec) -> Result<()> { let (tc_components, tools) = split_components(components); @@ -231,7 +241,7 @@ impl<'a> InstallConfiguration<'a> { self.inc_progress(sub_progress_delta)?; } - self.install_record.write()?; + self.get_install_record_mut_unchecked().write()?; Ok(()) } @@ -260,14 +270,14 @@ impl<'a> InstallConfiguration<'a> { self.cargo_is_installed = true; // Add the rust info to the fingerprint. - self.install_record + self.get_install_record_mut_unchecked() .add_rust_record(manifest.rust_version(), optional_components); // record meta info // TODO(?): Maybe this should be moved as a separate step? - self.install_record + self.get_install_record_mut_unchecked() .clone_toolkit_meta_from_manifest(manifest); // write changes - self.install_record.write()?; + self.get_install_record_mut_unchecked().write()?; self.inc_progress(30.0) } @@ -320,7 +330,8 @@ impl<'a> InstallConfiguration<'a> { } }; - self.install_record.add_tool_record(name, record); + self.get_install_record_mut_unchecked() + .add_tool_record(name, record); Ok(()) } @@ -414,12 +425,13 @@ impl InstallConfiguration<'_> { .update(self, manifest)?; // Add the rust info to the fingerprint. - self.install_record.update_rust(manifest.rust_version()); + self.get_install_record_mut_unchecked() + .update_rust(manifest.rust_version()); // record meta info - self.install_record + self.get_install_record_mut_unchecked() .clone_toolkit_meta_from_manifest(manifest); // write changes - self.install_record.write()?; + self.get_install_record_mut_unchecked().write()?; self.inc_progress(60.0) } @@ -495,10 +507,10 @@ mod tests { let install_root = tempfile::Builder::new().tempdir_in(&cache_dir).unwrap(); let manifest = get_toolset_manifest(None, false).unwrap(); - let config = InstallConfiguration::new(install_root.path(), &manifest).unwrap(); + let mut config = InstallConfiguration::new(install_root.path(), &manifest).unwrap(); config.setup().unwrap(); - assert!(config.install_record.name.is_none()); + assert!(config.get_install_record_mut_unchecked().name.is_none()); assert!(install_root .path() .join(InstallationRecord::FILENAME) diff --git a/src/core/parser/fingerprint.rs b/src/core/parser/fingerprint.rs index e1da06b6..2c50e715 100644 --- a/src/core/parser/fingerprint.rs +++ b/src/core/parser/fingerprint.rs @@ -38,10 +38,7 @@ impl TomlParser for InstallationRecord { where Self: Sized + serde::de::DeserializeOwned, { - assert!( - root.as_ref().is_dir(), - "install record needs to be loaded from a directory" - ); + utils::ensure_dir(root.as_ref())?; let fp_path = root.as_ref().join(Self::FILENAME); if fp_path.is_file() { From 896679a2a3fd0e92e07eb0b0b332a485166b0918 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Thu, 26 Dec 2024 15:01:05 +0800 Subject: [PATCH 3/5] fixed a critical bug that is causing tool's installation fail, becausing it's trying to enter into a file path --- src/core/install.rs | 3 +-- src/utils/extraction.rs | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/install.rs b/src/core/install.rs index 948c0dec..4a751a4f 100644 --- a/src/core/install.rs +++ b/src/core/install.rs @@ -392,8 +392,7 @@ impl<'a> InstallConfiguration<'a> { /// otherwise this will copy that file into dest. fn extract_or_copy_to(&self, maybe_file: &Path, dest: &Path) -> Result { if let Ok(mut extractable) = Extractable::load(maybe_file) { - extractable.extract_then_skip_solo_dir(dest, Some("bin"))?; - Ok(dest.to_path_buf()) + extractable.extract_then_skip_solo_dir(dest, Some("bin")) } else { utils::copy_into(maybe_file, dest) } diff --git a/src/utils/extraction.rs b/src/utils/extraction.rs index 60fa4bea..39ef22fd 100644 --- a/src/utils/extraction.rs +++ b/src/utils/extraction.rs @@ -132,7 +132,13 @@ impl<'a> Extractable<'a> { stop: Option, ) -> Result { fn inner_>(root: &Path, stop: Option) -> Result { - if let [sub_dir] = super::walk_dir(root, false)?.as_slice() { + let sub_entries = if root.is_dir() { + super::walk_dir(root, false)? + } else { + return Ok(root.to_path_buf()); + }; + + if let [sub_dir] = sub_entries.as_slice() { if matches!(stop, Some(ref keyword) if filename_matches_keyword(sub_dir, keyword)) { Ok(root.to_path_buf()) } else { From a0f68ec28fcdd188dbdad6961e7344b8d4ce4f31 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Thu, 26 Dec 2024 16:45:01 +0800 Subject: [PATCH 4/5] use `no-self-update` when update via rustup & fix a panic introduced by last commit --- src/core/install.rs | 40 +++++++++++++--------------------------- src/core/rustup.rs | 2 +- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/core/install.rs b/src/core/install.rs index 4a751a4f..77d5c325 100644 --- a/src/core/install.rs +++ b/src/core/install.rs @@ -74,7 +74,7 @@ pub struct InstallConfiguration<'a> { pub rustup_update_root: Url, /// Indicates whether `cargo` was already installed, useful when installing third-party tools. pub cargo_is_installed: bool, - install_record: Option, + install_record: InstallationRecord, pub(crate) progress_indicator: Option>, manifest: &'a ToolsetManifest, insecure: bool, @@ -90,7 +90,8 @@ impl<'a> InstallConfiguration<'a> { pub fn new(install_dir: &'a Path, manifest: &'a ToolsetManifest) -> Result { Ok(Self { install_dir: install_dir.to_path_buf(), - install_record: None, + // Note: `InstallationRecord::load` creates `install_dir` if it does not exist + install_record: InstallationRecord::load(install_dir)?, cargo_registry: None, rustup_dist_server: default_rustup_dist_server().clone(), rustup_update_root: default_rustup_update_root().clone(), @@ -109,10 +110,6 @@ impl<'a> InstallConfiguration<'a> { info!("{}", t!("install_init", dir = install_dir.display())); - // Create a new folder to hold installation (`InstallationRecord::load` ensures - // its parent directory) - self.install_record = Some(InstallationRecord::load(install_dir)?); - // Create a copy of the manifest which is later used for component management. let manifest_out_path = install_dir.join(ToolsetManifest::FILENAME); utils::write_file(manifest_out_path, &manifest.to_toml()?, false)?; @@ -138,15 +135,6 @@ impl<'a> InstallConfiguration<'a> { Ok(()) } - fn get_install_record_mut_unchecked(&mut self) -> &mut InstallationRecord { - self.install_record.as_mut().unwrap_or_else(|| { - panic!( - "internal error: attempt to get installation record before it was initialized \ - make sure to call `setup` after creating a new `InstallConfiguration`" - ) - }) - } - pub fn install(mut self, components: Vec) -> Result<()> { let (tc_components, tools) = split_components(components); @@ -241,7 +229,7 @@ impl<'a> InstallConfiguration<'a> { self.inc_progress(sub_progress_delta)?; } - self.get_install_record_mut_unchecked().write()?; + self.install_record.write()?; Ok(()) } @@ -270,14 +258,14 @@ impl<'a> InstallConfiguration<'a> { self.cargo_is_installed = true; // Add the rust info to the fingerprint. - self.get_install_record_mut_unchecked() + self.install_record .add_rust_record(manifest.rust_version(), optional_components); // record meta info // TODO(?): Maybe this should be moved as a separate step? - self.get_install_record_mut_unchecked() + self.install_record .clone_toolkit_meta_from_manifest(manifest); // write changes - self.get_install_record_mut_unchecked().write()?; + self.install_record.write()?; self.inc_progress(30.0) } @@ -330,8 +318,7 @@ impl<'a> InstallConfiguration<'a> { } }; - self.get_install_record_mut_unchecked() - .add_tool_record(name, record); + self.install_record.add_tool_record(name, record); Ok(()) } @@ -423,14 +410,13 @@ impl InstallConfiguration<'_> { .insecure(self.insecure) .update(self, manifest)?; + let record = &mut self.install_record; // Add the rust info to the fingerprint. - self.get_install_record_mut_unchecked() - .update_rust(manifest.rust_version()); + record.update_rust(manifest.rust_version()); // record meta info - self.get_install_record_mut_unchecked() - .clone_toolkit_meta_from_manifest(manifest); + record.clone_toolkit_meta_from_manifest(manifest); // write changes - self.get_install_record_mut_unchecked().write()?; + record.write()?; self.inc_progress(60.0) } @@ -509,7 +495,7 @@ mod tests { let mut config = InstallConfiguration::new(install_root.path(), &manifest).unwrap(); config.setup().unwrap(); - assert!(config.get_install_record_mut_unchecked().name.is_none()); + assert!(config.install_record.name.is_none()); assert!(install_root .path() .join(InstallationRecord::FILENAME) diff --git a/src/core/rustup.rs b/src/core/rustup.rs index f5c8a8d0..2bf16474 100644 --- a/src/core/rustup.rs +++ b/src/core/rustup.rs @@ -109,7 +109,7 @@ impl ToolchainInstaller { let rustup = ensure_rustup(config, manifest, self.insecure)?; let tc_ver = manifest.rust_version(); - utils::run!(&rustup, "toolchain", "add", tc_ver) + utils::run!(&rustup, "toolchain", "add", tc_ver, "--no-self-update") } // Rustup self uninstall all the components and toolchains. From d3a2915ed282854b05162b75daf6c6e5081a9063 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Thu, 26 Dec 2024 17:06:24 +0800 Subject: [PATCH 5/5] fix incorrect version for generated mocked manager --- rim_dev/src/mocked/manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rim_dev/src/mocked/manager.rs b/rim_dev/src/mocked/manager.rs index ddf18cb8..66837fab 100644 --- a/rim_dev/src/mocked/manager.rs +++ b/rim_dev/src/mocked/manager.rs @@ -83,7 +83,7 @@ fn gen_release_toml(version: &str) -> Result<()> { /// The target version will always be one major release ahead of the current version, /// so if the current version is `1.0.0`, the target version will be `2.0.0`. fn mocked_ws_version() -> String { - let ws_manifest_content = include_str!("../../Cargo.toml"); + let ws_manifest_content = include_str!("../../../Cargo.toml"); let cur_ver = ws_manifest_content .lines() .find_map(|line| {