Delete the maintenance tool binary itself after uninstall (closes #1)

This commit is contained in:
James 2018-08-08 20:22:59 +10:00
parent 19bec5d80c
commit 3ff35b2e62
3 changed files with 63 additions and 1 deletions

View file

@ -63,6 +63,8 @@ pub struct InstallerFramework {
pub install_path: Option<PathBuf>,
pub preexisting_install: bool,
pub is_launcher: bool,
// If we just completed an uninstall, and we should clean up after ourselves.
pub burn_after_exit: bool,
pub launcher_path: Option<String>,
}
@ -199,6 +201,7 @@ impl InstallerFramework {
.map_err(|x| format!("Failed to delete metadata: {:?}", x))?;
// Logging will have to be done later
self.burn_after_exit = true;
Ok(())
}
@ -254,6 +257,7 @@ impl InstallerFramework {
install_path: None,
preexisting_install: false,
is_launcher: false,
burn_after_exit: false,
launcher_path: None,
}
}
@ -280,6 +284,7 @@ impl InstallerFramework {
install_path: Some(path),
preexisting_install: true,
is_launcher: false,
burn_after_exit: false,
launcher_path: None,
})
}

View file

@ -11,6 +11,8 @@ mod natives {
use logging::LoggingErrors;
use std::env;
use std::path::PathBuf;
use std::process::Command;
include!(concat!(env!("OUT_DIR"), "/interop.rs"));
@ -59,10 +61,39 @@ mod natives {
)),
}
}
/// Cleans up the installer
pub fn burn_on_exit(path: PathBuf) {
// Need a cmd workaround here.
let tool = path.join("maintenancetool.exe");
let tool = tool
.to_str()
.log_expect("Unable to convert tool path to string")
.replace(" ", "\\ ");
let log = path.join("installer.log");
let log = log
.to_str()
.log_expect("Unable to convert log path to string")
.replace(" ", "\\ ");
let target_arguments = format!("ping 127.0.0.1 -n 6 > nul && del {} {}", tool, log);
info!("Launching cmd with {:?}", target_arguments);
Command::new("C:\\Windows\\system32\\cmd.exe")
.arg("/C")
.arg(&target_arguments)
.spawn()
.log_expect("Unable to start child process");
}
}
#[cfg(not(windows))]
mod natives {
use std::fs::remove_file;
use std::path::PathBuf;
pub fn create_shortcut(
name: &str,
description: &str,
@ -75,6 +106,20 @@ mod natives {
Ok("".to_string())
}
/// Cleans up the installer
pub fn burn_on_exit(path: PathBuf) {
// Thank god for *nix platforms
if let Err(e) = remove_file(path.join("/maintenancetool")) {
// No regular logging now.
eprintln!("Failed to delete maintenancetool: {:?}", e);
};
if let Err(e) = remove_file(path.join("/installer.log")) {
// No regular logging now.
eprintln!("Failed to delete installer log: {:?}", e);
};
}
}
pub use self::natives::*;

View file

@ -19,6 +19,7 @@ use url::form_urlencoded;
use std::collections::HashMap;
use std::net::SocketAddr;
use std::process::exit;
use std::process::Command;
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::sync::RwLock;
@ -30,12 +31,13 @@ use installer::InstallMessage;
use installer::InstallerFramework;
use logging::LoggingErrors;
use std::process::Command;
use http;
use config::Config;
use native;
#[derive(Serialize)]
struct FileSelection {
path: Option<String>,
@ -204,6 +206,16 @@ impl Service for WebService {
.log_expect("Unable to start child process");
}
if framework.burn_after_exit {
let path = framework
.install_path
.clone()
.log_expect("No install path when one should have existed?");
println!("Base path: {:?}", path);
native::burn_on_exit(path);
}
exit(0);
}
// Gets properties such as if the application is in maintenance mode