From b800fda2bf4982cd2a07b81534b90614951933bb Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sat, 18 Nov 2023 13:59:16 -0800 Subject: [PATCH 1/3] Remove symlink. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/cli/src/commands/clean.rs | 2 +- crates/core/src/tool.rs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7094d7caa..6d6e42c50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3168,9 +3168,9 @@ dependencies = [ [[package]] name = "starbase_utils" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db5c15177ddbb9ddef8751911d8b75c02b5a9ea11d9a24a44951de97bd8a722" +checksum = "9af464d976956393070880234f8d9f3509f04555266174abfd9b11386cdce4bc" dependencies = [ "dirs 5.0.1", "fs4", diff --git a/Cargo.toml b/Cargo.toml index 94bab04f9..d40c04ae0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ starbase_archive = { version = "0.2.4", features = [ starbase_events = "0.2.2" starbase_sandbox = { version = "0.1.12" } starbase_styles = "0.1.16" -starbase_utils = { version = "0.3.8", default-features = false, features = [ +starbase_utils = { version = "0.3.11", default-features = false, features = [ "json", "toml", ] } diff --git a/crates/cli/src/commands/clean.rs b/crates/cli/src/commands/clean.rs index f191b6d2c..eb69d26fa 100644 --- a/crates/cli/src/commands/clean.rs +++ b/crates/cli/src/commands/clean.rs @@ -206,7 +206,7 @@ pub async fn purge_tool(id: &Id, yes: bool) -> SystemResult { // Delete binaries for bin in tool.get_bin_locations()? { - fs::remove_file(bin.path)?; + fs::remove_link(bin.path)?; } // Delete shims diff --git a/crates/core/src/tool.rs b/crates/core/src/tool.rs index 6e0a7ace5..fce22c331 100644 --- a/crates/core/src/tool.rs +++ b/crates/core/src/tool.rs @@ -1456,7 +1456,7 @@ impl Tool { "Creating binary symlink" ); - fs::remove_file(&output_path)?; + fs::remove_link(&output_path)?; #[cfg(windows)] { @@ -1556,9 +1556,9 @@ impl Tool { // If no more default version, delete the symlink, // otherwise the OS will throw errors for missing sources - if self.manifest.default_version.is_none() { + if self.manifest.default_version.is_none() || self.manifest.installed_versions.is_empty() { for bin in self.get_bin_locations()? { - fs::remove_file(bin.path)?; + fs::remove_link(bin.path)?; } } @@ -1579,7 +1579,7 @@ impl Tool { "Cleaning up temporary files and downloads" ); - fs::remove(self.get_temp_dir())?; + fs::remove_dir_all(self.get_temp_dir())?; Ok(()) } From e73bb2aede4f0b011e8a29d5251dfe499c36467e Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sat, 18 Nov 2023 14:00:01 -0800 Subject: [PATCH 2/3] Update changelog. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6af66e8..88f901191 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ ## Unreleased +#### 🐞 Fixes + +- Fixed an issue where broken symlinks would fail to be removed. This would result in subsequent "File exists (os error 17)" errors. + #### ⚙️ Internal - Updated Rust to v1.74. From 581ab7aa98145aa8b582cf4d044326c212b5840e Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sat, 18 Nov 2023 14:31:13 -0800 Subject: [PATCH 3/3] Fix test. --- crates/cli/tests/clean_test.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/cli/tests/clean_test.rs b/crates/cli/tests/clean_test.rs index 17fcf4c7c..43020f063 100644 --- a/crates/cli/tests/clean_test.rs +++ b/crates/cli/tests/clean_test.rs @@ -34,8 +34,17 @@ mod clean { #[test] fn purges_tool_bin() { let sandbox = create_empty_sandbox(); - sandbox.create_file("bin/node", ""); - sandbox.create_file("bin/node.exe", ""); + sandbox.create_file("tools/node/fake/file", ""); + sandbox.create_file("bin/other", ""); + + let bin = sandbox.path().join(if cfg!(windows) { + "bin/node.exe" + } else { + "bin/node" + }); + + #[allow(deprecated)] + std::fs::soft_link(sandbox.path().join("tools/node/fake/file"), &bin).unwrap(); let mut cmd = create_proto_command(sandbox.path()); cmd.arg("clean") @@ -45,11 +54,8 @@ mod clean { .assert() .success(); - if cfg!(windows) { - assert!(!sandbox.path().join("bin/node.exe").exists()); - } else { - assert!(!sandbox.path().join("bin/node").exists()); - } + assert!(!bin.exists()); + assert!(bin.symlink_metadata().is_err()); } #[test]