Skip to content

ref: Simplify set_executable_mode #2433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
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
17 changes: 5 additions & 12 deletions src/utils/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,14 @@ pub fn is_writable<P: AsRef<Path>>(path: P) -> bool {
/// Set the mode of a path to 755 if we're on a Unix machine, otherwise
/// don't do anything with the given path.
#[cfg(not(feature = "managed"))]
#[cfg(not(windows))]
pub fn set_executable_mode<P: AsRef<Path>>(path: P) -> Result<()> {
#[cfg(not(windows))]
fn exec<P: AsRef<Path>>(path: P) -> io::Result<()> {
use std::os::unix::fs::PermissionsExt;
let mut perm = fs::metadata(&path)?.permissions();
perm.set_mode(0o755);
fs::set_permissions(&path, perm)
}
use std::os::unix::fs::PermissionsExt;

#[cfg(windows)]
fn exec<P: AsRef<Path>>(_path: P) -> io::Result<()> {
Ok(())
}
let mut perm = fs::metadata(&path)?.permissions();
perm.set_mode(0o755);
fs::set_permissions(&path, perm)?;

exec(path)?;
Ok(())
}

Expand Down
6 changes: 5 additions & 1 deletion src/utils/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use crate::api::{Api, SentryCliRelease};
use crate::config::Config;
use crate::constants::{APP_NAME, VERSION};
#[cfg(not(feature = "managed"))]
use crate::utils::fs::{is_writable, set_executable_mode};
use crate::utils::fs::is_writable;
#[cfg(not(windows))]
#[cfg(not(feature = "managed"))]
use crate::utils::fs::set_executable_mode;
#[cfg(not(feature = "managed"))]
use crate::utils::system::QuietExit;
use crate::utils::system::{is_homebrew_install, is_npm_install};
Expand Down Expand Up @@ -171,6 +174,7 @@ impl SentryCliUpdateInfo {
}
};

#[cfg(not(windows))]
set_executable_mode(&tmp_path)?;
rename_exe(&exe, &tmp_path, elevate)?;
Ok(())
Expand Down
Loading