Skip to content

Commit

Permalink
Always uninstall before installing (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson authored Jul 29, 2024
1 parent 0649aa9 commit a0fe89d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl PluginifyCommand {
}

if self.install {
spin::plugin_install_file(manifest_path)?;
spin::plugin_install_file(&manifest.name, manifest_path)?;
}

Ok(())
Expand Down
22 changes: 20 additions & 2 deletions src/spin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
use std::path::PathBuf;
use std::process::Command;

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

Command::new(spin)
let uninstall_result = Command::new(&spin)
.arg("plugin")
.arg("uninstall")
.arg(name)
.spawn()?
.wait();

if is_fail(&uninstall_result) {
eprintln!("Failed to uninstall old plugin - continuing");
}

Command::new(&spin)
.arg("plugin")
.arg("install")
.arg("--file")
Expand All @@ -15,3 +26,10 @@ pub fn plugin_install_file(file: PathBuf) -> Result<(), std::io::Error> {

Ok(())
}

fn is_fail(res: &std::io::Result<std::process::ExitStatus>) -> bool {
match res {
Err(_) => true,
Ok(st) => st.code() != Some(0),
}
}

0 comments on commit a0fe89d

Please sign in to comment.