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_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| { 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" diff --git a/src/core/install.rs b/src/core/install.rs index fb76b7b8..77d5c325 100644 --- a/src/core/install.rs +++ b/src/core/install.rs @@ -90,6 +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(), + // 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(), @@ -103,15 +104,12 @@ 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 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)?; @@ -381,8 +379,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) } @@ -413,13 +410,13 @@ impl InstallConfiguration<'_> { .insecure(self.insecure) .update(self, manifest)?; + let record = &mut self.install_record; // Add the rust info to the fingerprint. - self.install_record.update_rust(manifest.rust_version()); + record.update_rust(manifest.rust_version()); // record meta info - self.install_record - .clone_toolkit_meta_from_manifest(manifest); + record.clone_toolkit_meta_from_manifest(manifest); // write changes - self.install_record.write()?; + record.write()?; self.inc_progress(60.0) } @@ -495,7 +492,7 @@ 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()); 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() { 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. 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 {