Skip to content

Commit 359bbfb

Browse files
committed
Fixed sudo check
1 parent 7e1b546 commit 359bbfb

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sentry-cli"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
55

66
[lib]

src/sentrycli/commands/update.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use hyper::method::Method;
1313
use url::Url;
1414
use serde_json;
1515

16+
use utils;
1617
use CliResult;
1718
use commands::Config;
1819

@@ -117,7 +118,7 @@ pub fn make_app<'a, 'b: 'a>(app: App<'a, 'b>) -> App<'a, 'b>
117118

118119
pub fn execute<'a>(_matches: &ArgMatches<'a>, _config: &Config) -> CliResult<()> {
119120
let exe = env::current_exe()?;
120-
let need_sudo = fs::metadata(&exe)?.permissions().readonly();
121+
let need_sudo = !utils::is_writable(&exe);
121122
let latest_release = get_latest_release()?;
122123
let tmp_path = if need_sudo {
123124
env::temp_dir().join(".sentry-cli.part")
@@ -132,8 +133,7 @@ pub fn execute<'a>(_matches: &ArgMatches<'a>, _config: &Config) -> CliResult<()>
132133
return Ok(());
133134
}
134135

135-
println!("Executable location: {}", exe.display());
136-
println!("Download URL: {}", latest_release.download_url);
136+
println!("Updating executable at {}", exe.display());
137137

138138
match download_url(&latest_release.download_url, &tmp_path) {
139139
Err(err) => {

src/sentrycli/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,7 @@ pub fn get_sha1_checksum(path: &Path) -> CliResult<String> {
8686
}
8787
Ok(sha.hexdigest())
8888
}
89+
90+
pub fn is_writable<P: AsRef<Path>>(path: P) -> bool {
91+
fs::OpenOptions::new().write(true).open(&path).map(|_| true).unwrap_or(false)
92+
}

0 commit comments

Comments
 (0)