Skip to content

Commit c9d83eb

Browse files
ref(utils): Remove allow(dead_code) from update utils (#2216)
Instead, mark all code that is not needed for the `managed` build with `cfg(not(feature = "managed"))`.
1 parent 52d10e7 commit c9d83eb

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

src/api/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl Api {
284284

285285
/// Convenience method that downloads a file into the given file object
286286
/// and show a progress bar
287+
#[cfg(not(feature = "managed"))]
287288
pub fn download_with_progress(&self, url: &str, dst: &mut File) -> ApiResult<ApiResponse> {
288289
self.request(Method::Get, url, None)?
289290
.follow_location(true)?
@@ -329,12 +330,13 @@ impl Api {
329330

330331
if resp.status() == 200 {
331332
let info: RegistryRelease = resp.convert()?;
332-
for (filename, download_url) in info.file_urls {
333+
for (filename, _download_url) in info.file_urls {
333334
info!("Found asset {}", filename);
334335
if filename == ref_name {
335336
return Ok(Some(SentryCliRelease {
336337
version: info.version,
337-
download_url,
338+
#[cfg(not(feature = "managed"))]
339+
download_url: _download_url,
338340
}));
339341
}
340342
}
@@ -2164,6 +2166,7 @@ struct RegistryRelease {
21642166
/// Information about sentry CLI releases
21652167
pub struct SentryCliRelease {
21662168
pub version: String,
2169+
#[cfg(not(feature = "managed"))]
21672170
pub download_url: String,
21682171
}
21692172

src/utils/fs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl Drop for TempFile {
124124
}
125125

126126
/// Checks if a path is writable.
127+
#[cfg(not(feature = "managed"))]
127128
pub fn is_writable<P: AsRef<Path>>(path: P) -> bool {
128129
fs::OpenOptions::new()
129130
.write(true)
@@ -134,6 +135,7 @@ pub fn is_writable<P: AsRef<Path>>(path: P) -> bool {
134135

135136
/// Set the mode of a path to 755 if we're on a Unix machine, otherwise
136137
/// don't do anything with the given path.
138+
#[cfg(not(feature = "managed"))]
137139
pub fn set_executable_mode<P: AsRef<Path>>(path: P) -> Result<()> {
138140
#[cfg(not(windows))]
139141
fn exec<P: AsRef<Path>>(path: P) -> io::Result<()> {

src/utils/progress.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl Deref for ProgressBar {
7878
pub enum ProgressBarMode {
7979
Disabled,
8080
Request,
81+
#[cfg(not(feature = "managed"))]
8182
Response,
8283
Shared((Arc<ProgressBar>, u64, usize, Arc<RwLock<Vec<u64>>>)),
8384
}
@@ -95,6 +96,12 @@ impl ProgressBarMode {
9596

9697
/// Returns whether a progress bar should be displayed during download.
9798
pub fn response(&self) -> bool {
98-
matches!(*self, ProgressBarMode::Response)
99+
#[cfg(not(feature = "managed"))]
100+
let rv = matches!(*self, ProgressBarMode::Response);
101+
102+
#[cfg(feature = "managed")]
103+
let rv = false;
104+
105+
rv
99106
}
100107
}

src/utils/update.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
#![allow(dead_code)] // a ton of functions/fields might be unused based on the `managed` feature
2-
1+
#[cfg(not(feature = "managed"))]
32
use std::env;
43
use std::fs;
54
use std::io;
65
use std::io::Write;
6+
#[cfg(not(feature = "managed"))]
77
use std::path::Path;
88

9-
use anyhow::{bail, format_err, Result};
9+
#[cfg(not(feature = "managed"))]
10+
use anyhow::bail;
11+
use anyhow::{format_err, Result};
1012
use chrono::{DateTime, Duration, Utc};
1113
use console::{style, user_attended};
1214
use if_chain::if_chain;
@@ -17,8 +19,11 @@ use serde::{Deserialize, Serialize};
1719
use crate::api::{Api, SentryCliRelease};
1820
use crate::config::Config;
1921
use crate::constants::{APP_NAME, VERSION};
22+
#[cfg(not(feature = "managed"))]
2023
use crate::utils::fs::{is_writable, set_executable_mode};
21-
use crate::utils::system::{is_homebrew_install, is_npm_install, QuietExit};
24+
#[cfg(not(feature = "managed"))]
25+
use crate::utils::system::QuietExit;
26+
use crate::utils::system::{is_homebrew_install, is_npm_install};
2227

2328
#[cfg(windows)]
2429
fn rename_exe(exe: &Path, downloaded_path: &Path, elevate: bool) -> Result<()> {
@@ -52,7 +57,7 @@ fn rename_exe(exe: &Path, downloaded_path: &Path, elevate: bool) -> Result<()> {
5257
Ok(())
5358
}
5459

55-
#[cfg(not(windows))]
60+
#[cfg(not(any(feature = "managed", windows)))]
5661
fn rename_exe(exe: &Path, downloaded_path: &Path, elevate: bool) -> Result<()> {
5762
if elevate {
5863
println!("Need to sudo to overwrite {}", exe.display());
@@ -119,6 +124,7 @@ impl SentryCliUpdateInfo {
119124
self.latest_release.is_some()
120125
}
121126

127+
#[cfg(not(feature = "managed"))]
122128
pub fn is_latest_version(&self) -> bool {
123129
self.latest_version() == VERSION
124130
}
@@ -135,6 +141,7 @@ impl SentryCliUpdateInfo {
135141
}
136142
}
137143

144+
#[cfg(not(feature = "managed"))]
138145
pub fn download_url(&self) -> Result<&str> {
139146
if let Some(ref rel) = self.latest_release {
140147
Ok(rel.download_url.as_str())
@@ -143,6 +150,7 @@ impl SentryCliUpdateInfo {
143150
}
144151
}
145152

153+
#[cfg(not(feature = "managed"))]
146154
pub fn download(&self) -> Result<()> {
147155
let exe = env::current_exe()?;
148156
let elevate = !is_writable(&exe);
@@ -175,10 +183,12 @@ pub fn get_latest_sentrycli_release() -> Result<SentryCliUpdateInfo> {
175183
})
176184
}
177185

186+
#[cfg(not(feature = "managed"))]
178187
pub fn can_update_sentrycli() -> bool {
179188
!is_homebrew_install() && !is_npm_install()
180189
}
181190

191+
#[cfg(not(feature = "managed"))]
182192
pub fn assert_updatable() -> Result<()> {
183193
if is_homebrew_install() {
184194
println!("This installation of sentry-cli is managed through homebrew");

0 commit comments

Comments
 (0)