use starbase_utils::fs::{self, FsError};
use std::path::Path;
pub fn self_replace(
current_exe: &Path,
replace_with: &Path,
relocate_to: &Path,
) -> Result<(), FsError> {
let exe = current_exe.canonicalize().map_err(|error| FsError::Read {
path: current_exe.to_path_buf(),
error: Box::new(error),
})?;
fs::rename(exe, relocate_to)?;
let mut temp_exe = current_exe.to_path_buf();
temp_exe.set_extension("temp.exe");
fs::copy_file(replace_with, &temp_exe)?;
fs::rename(temp_exe, current_exe)?;
Ok(())
}