image_optimizer/updater/
executable_manager.rs

1use anyhow::Result;
2use std::path::PathBuf;
3
4/// Gets the path to the current executable file.
5///
6/// This function retrieves the filesystem path to the currently running executable,
7/// which is needed for the self-update process to know which file to replace.
8/// It wraps Rust's `std::env::current_exe()` with proper error handling.
9///
10/// # Returns
11///
12/// Returns the `PathBuf` to the current executable file.
13///
14/// # Errors
15///
16/// Returns an error if the current executable path cannot be determined, which may
17/// happen in some restricted execution environments or if the executable has been
18/// deleted after startup.
19///
20/// # Examples
21///
22/// ```rust
23/// use image_optimizer::updater::executable_manager::get_current_executable;
24///
25/// # fn example() -> anyhow::Result<()> {
26/// let exe_path = get_current_executable()?;
27/// println!("Current executable: {}", exe_path.display());
28/// # Ok(())
29/// # }
30/// ```
31pub fn get_current_executable() -> Result<PathBuf> {
32    std::env::current_exe()
33        .map_err(|e| anyhow::anyhow!("Failed to get current executable path: {}", e))
34}