Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! versions or to uninstall themselves. On Unix systems this is a simple feat, but
//! on Windows a few hacks are needed which is why this crate exists.
//!
//! This is a useful operation when working with single-executable utilties that
//! This is a useful operation when working with single-executable utilities that
//! want to implement a form of self updating or self uninstallation.
//!
//! ## Self Deletion
Expand All @@ -20,7 +20,7 @@
//! ```
//!
//! On Windows self deletion requires some place in the folder the deletion is taking
//! place. This will prevent the abiltiy of the program to also delete the folder the
//! place. This will prevent the ability of the program to also delete the folder the
//! executable is placed in. To avoid this you can use the [`self_delete_outside_path`]
//! function which will ensure that the deletion does not take place in the path
//! provided if it's possible to do so. That way you can delete entire structures safely.
Expand Down Expand Up @@ -93,7 +93,7 @@
//! is that it requires that the new replacing executable has matching logic for the
//! cleanup. The second issue with this approach is that it requires either launching
//! the new executable or waiting for the executable to launch for natural reasons.
//! The former might not always be preferrable, the second leaves files lingering
//! The former might not always be preferable, the second leaves files lingering
//! around for an extended period of time.
//!
//! The third, and somewhat official solution is to use `MOVEFILE_DELAY_UNTIL_REBOOT`
Expand All @@ -120,6 +120,9 @@ mod unix;
#[cfg(windows)]
mod windows;

#[cfg(not(any(windows, unix)))]
compile_error!("self-replace cannot be built for this target (only windows and unix is supported)");

/// Deletes the executable in a platform independent manner.
///
/// The deletion on windows is delayed until the process shuts down. For updating
Expand Down Expand Up @@ -151,6 +154,11 @@ pub fn self_delete_at<P: AsRef<Path>>(exe: P) -> Result<(), io::Error> {
{
crate::windows::self_delete(exe.as_ref(), None)
}
#[cfg(not(any(windows, unix)))]
{
let _ = exe;
unimplemented!();
}
}

/// Like [`self_delete`] but accepts a path which must not be used for temporary operations.
Expand All @@ -170,6 +178,12 @@ pub fn self_delete_outside_path<P: AsRef<Path>>(p: P) -> Result<(), io::Error> {
{
crate::windows::self_delete(&exe, Some(p.as_ref()))
}
#[cfg(not(any(windows, unix)))]
{
let _ = p;
let _ = exe;
unimplemented!();
}
}

/// Replaces the running executable with a different one.
Expand Down Expand Up @@ -202,4 +216,9 @@ pub fn self_replace<P: AsRef<Path>>(new_executable: P) -> Result<(), io::Error>
{
crate::windows::self_replace(new_executable.as_ref())
}
#[cfg(not(any(windows, unix)))]
{
let _ = new_executable;
unimplemented!();
}
}