support admin server restart --force
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
7658387a74
commit
5edd391e83
4 changed files with 62 additions and 6 deletions
|
@ -34,3 +34,34 @@ pub fn available_parallelism() -> usize {
|
|||
.expect("Unable to query for available parallelism.")
|
||||
.get()
|
||||
}
|
||||
|
||||
/// Return a possibly corrected std::env::current_exe() even if the path is
|
||||
/// marked deleted.
|
||||
///
|
||||
/// # Safety
|
||||
/// This function is declared unsafe because the original result was altered for
|
||||
/// security purposes, and altering it back ignores those urposes and should be
|
||||
/// understood by the user.
|
||||
pub unsafe fn current_exe() -> Result<std::path::PathBuf> {
|
||||
use std::path::PathBuf;
|
||||
|
||||
let exe = std::env::current_exe()?;
|
||||
match exe.to_str() {
|
||||
None => Ok(exe),
|
||||
Some(str) => Ok(str
|
||||
.strip_suffix(" (deleted)")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or(exe)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine if the server's executable was removed or replaced. This is a
|
||||
/// specific check; useful for successful restarts. May not be available or
|
||||
/// accurate on all platforms; defaults to false.
|
||||
#[must_use]
|
||||
pub fn current_exe_deleted() -> bool {
|
||||
std::env::current_exe().map_or(false, |exe| {
|
||||
exe.to_str()
|
||||
.map_or(false, |exe| exe.ends_with(" (deleted)"))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue