Skip to content

Commit a0fe89d

Browse files
authored
Always uninstall before installing (#18)
1 parent 0649aa9 commit a0fe89d

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl PluginifyCommand {
111111
}
112112

113113
if self.install {
114-
spin::plugin_install_file(manifest_path)?;
114+
spin::plugin_install_file(&manifest.name, manifest_path)?;
115115
}
116116

117117
Ok(())

src/spin.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
use std::path::PathBuf;
22
use std::process::Command;
33

4-
pub fn plugin_install_file(file: PathBuf) -> Result<(), std::io::Error> {
4+
pub fn plugin_install_file(name: &str, file: PathBuf) -> Result<(), std::io::Error> {
55
let spin = std::env::var("SPIN_BIN_PATH").unwrap_or("spin".into());
66

7-
Command::new(spin)
7+
let uninstall_result = Command::new(&spin)
8+
.arg("plugin")
9+
.arg("uninstall")
10+
.arg(name)
11+
.spawn()?
12+
.wait();
13+
14+
if is_fail(&uninstall_result) {
15+
eprintln!("Failed to uninstall old plugin - continuing");
16+
}
17+
18+
Command::new(&spin)
819
.arg("plugin")
920
.arg("install")
1021
.arg("--file")
@@ -15,3 +26,10 @@ pub fn plugin_install_file(file: PathBuf) -> Result<(), std::io::Error> {
1526

1627
Ok(())
1728
}
29+
30+
fn is_fail(res: &std::io::Result<std::process::ExitStatus>) -> bool {
31+
match res {
32+
Err(_) => true,
33+
Ok(st) => st.code() != Some(0),
34+
}
35+
}

0 commit comments

Comments
 (0)