use starbase_utils::fs::{self, FsError};
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
pub fn self_replace(
current_exe: &Path,
replace_with: &Path,
relocate_to: &Path,
) -> miette::Result<()> {
let exe = current_exe.canonicalize().map_err(|error| FsError::Read {
path: current_exe.to_path_buf(),
error: Box::new(error),
})?;
let perms = fs::metadata(&exe)?.permissions();
fs::rename(exe, relocate_to)?;
fs::copy_file(replace_with, current_exe)?;
fs::update_perms(current_exe, Some(perms.mode()))?;
Ok(())
}