Skip to content

Commit 4306d2b

Browse files
ranfdevCopilot
andcommitted
Fix all clippy warnings
Resolve strict clippy warnings across touched modules and restore cached known distro map initialization performance behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2f16116 commit 4306d2b

16 files changed

Lines changed: 169 additions & 157 deletions

src/backends/distrobox/distrobox.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ pub struct Distrobox {
103103
cmd_factory: CmdFactory,
104104
}
105105

106+
type CommandResponse = (Command, Rc<dyn Fn() -> io::Result<String>>);
107+
106108
#[derive(Clone, Debug, PartialEq, Hash)]
107109
pub enum Status {
108110
Up(String),
@@ -530,11 +532,11 @@ impl DistroboxCommandRunnerResponse {
530532
commands
531533
}
532534

533-
fn wrap_err_fn(output: (Command, String)) -> (Command, Rc<dyn Fn() -> io::Result<String>>) {
535+
fn wrap_err_fn(output: (Command, String)) -> CommandResponse {
534536
(output.0, Rc::new(move || Ok(output.1.clone())))
535537
}
536538

537-
pub fn to_commands(self) -> Vec<(Command, Rc<dyn Fn() -> Result<String, io::Error>>)> {
539+
pub fn into_commands(self) -> Vec<CommandResponse> {
538540
match self {
539541
Self::Version => {
540542
let working_response = Self::build_version_response();
@@ -575,7 +577,7 @@ impl Distrobox {
575577
pub fn null_command_runner(responses: &[DistroboxCommandRunnerResponse]) -> CommandRunner {
576578
let mut builder = NullCommandRunnerBuilder::new();
577579
for res in responses {
578-
for (cmd, out) in res.clone().to_commands() {
580+
for (cmd, out) in res.clone().into_commands() {
579581
builder.cmd_full(cmd, move || out());
580582
}
581583
}
@@ -1427,7 +1429,7 @@ Categories=Utility;Security;";
14271429

14281430
#[test]
14291431
fn stub_responses() {
1430-
let cmd_outputs = DistroboxCommandRunnerResponse::new_list_common_distros().to_commands();
1432+
let cmd_outputs = DistroboxCommandRunnerResponse::new_list_common_distros().into_commands();
14311433
assert_eq!(
14321434
cmd_outputs[0].1().unwrap(),
14331435
"ID | NAME | STATUS | IMAGE
@@ -1452,14 +1454,17 @@ Categories=Utility;Security;";
14521454
fn stub_exported_apps_generates_valid_toml() {
14531455
// Verify that new_common_exported_apps generates valid TOML that can be parsed
14541456
let exported_apps = DistroboxCommandRunnerResponse::new_common_exported_apps();
1455-
let commands = exported_apps.to_commands();
1457+
let commands = exported_apps.into_commands();
14561458

14571459
// Find the command that should contain TOML output (distrobox enter ... sh -c ...)
14581460
let toml_command = commands
14591461
.iter()
14601462
.find(|(cmd, _)| {
14611463
cmd.program.to_string_lossy().contains("distrobox")
1462-
&& cmd.args.iter().any(|arg| arg.to_string_lossy() == "enter")
1464+
&& cmd
1465+
.args
1466+
.iter()
1467+
.any(|arg: &std::ffi::OsString| arg.to_string_lossy() == "enter")
14631468
})
14641469
.expect("Should have a TOML-generating command");
14651470

src/backends/distrobox/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod command;
2+
#[allow(clippy::module_inception)]
23
mod distrobox;
34

45
pub use distrobox::*;

src/backends/supported_terminals.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ impl TerminalRepository {
215215
let mut found_terminals = Vec::new();
216216
for terminal in FLATPAK_TERMINAL_CANDIDATES.iter() {
217217
// Extract app_id from extra_args (e.g., ["run", "org.gnome.Console"])
218-
if let Some(app_id) = terminal.extra_args.get(1) {
219-
if installed_apps.contains(app_id.as_str()) {
220-
found_terminals.push(terminal.clone());
221-
}
218+
if let Some(app_id) = terminal.extra_args.get(1)
219+
&& installed_apps.contains(app_id.as_str())
220+
{
221+
found_terminals.push(terminal.clone());
222222
}
223223
}
224224

src/dialogs/create_distrobox_dialog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ impl CreateDistroboxDialog {
972972
)));
973973

974974
let add_volume_button = adw::ButtonRow::builder()
975-
.title(&gettext("Add Volume"))
975+
.title(gettext("Add Volume"))
976976
.build();
977977
add_volume_button.connect_activated(clone!(
978978
#[weak(rename_to=this)]

src/dialogs/create_distrobox_helpers.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ fn compare_version_vec(a: &[u64], b: &[u64]) -> std::cmp::Ordering {
2727
pub fn split_repo_tag_digest(s: &str) -> (&str, Option<&str>, Option<&str>) {
2828
// Return (repo, tag_opt, digest_opt)
2929
let last_slash = s.rfind('/');
30-
if let Some(at_pos) = s.rfind('@') {
31-
if last_slash.map_or(true, |ls| at_pos > ls) {
32-
// If there is a tag before the @ (colon after last slash), strip it from repo
33-
let before_at = &s[..at_pos];
34-
if let Some(col_pos) = before_at.rfind(':') {
35-
if last_slash.map_or(true, |ls| col_pos > ls) {
36-
return (&before_at[..col_pos], None, Some(&s[at_pos + 1..]));
37-
}
38-
}
39-
return (before_at, None, Some(&s[at_pos + 1..]));
30+
if let Some(at_pos) = s.rfind('@')
31+
&& last_slash.is_none_or(|ls| at_pos > ls)
32+
{
33+
// If there is a tag before the @ (colon after last slash), strip it from repo
34+
let before_at = &s[..at_pos];
35+
if let Some(col_pos) = before_at.rfind(':')
36+
&& last_slash.is_none_or(|ls| col_pos > ls)
37+
{
38+
return (&before_at[..col_pos], None, Some(&s[at_pos + 1..]));
4039
}
40+
return (before_at, None, Some(&s[at_pos + 1..]));
4141
}
42-
if let Some(col_pos) = s.rfind(':') {
43-
if last_slash.map_or(true, |ls| col_pos > ls) {
44-
return (&s[..col_pos], Some(&s[col_pos + 1..]), None);
45-
}
42+
if let Some(col_pos) = s.rfind(':')
43+
&& last_slash.is_none_or(|ls| col_pos > ls)
44+
{
45+
return (&s[..col_pos], Some(&s[col_pos + 1..]), None);
4646
}
4747
(s, None, None)
4848
}
@@ -157,10 +157,10 @@ pub fn derive_image_prefill(
157157
// 1) try to find latest (case-insensitive)
158158
for img in &matching {
159159
let (_repo, tag_opt, _digest) = split_repo_tag_digest(img.as_str());
160-
if let Some(tag) = tag_opt {
161-
if tag.eq_ignore_ascii_case("latest") {
162-
return (filter, Some((*img).clone()));
163-
}
160+
if let Some(tag) = tag_opt
161+
&& tag.eq_ignore_ascii_case("latest")
162+
{
163+
return (filter, Some((*img).clone()));
164164
}
165165
}
166166

@@ -185,7 +185,7 @@ pub fn derive_image_prefill(
185185
if let Some(cap) = VERSION_RE.captures(&tag_l) {
186186
let ver = &cap["ver"];
187187
let nums: Vec<u64> = ver
188-
.split(|c| c == '.' || c == '_' || c == '-')
188+
.split(['.', '_', '-'])
189189
.filter_map(|p| p.parse::<u64>().ok())
190190
.collect();
191191
if !nums.is_empty() {
@@ -204,10 +204,10 @@ pub fn derive_image_prefill(
204204
// 4) fallback: pick first non-edge matching
205205
for img in &matching {
206206
let (_repo, tag_opt, _digest) = split_repo_tag_digest(img.as_str());
207-
if let Some(tag) = tag_opt {
208-
if tag.eq_ignore_ascii_case("edge") {
209-
continue;
210-
}
207+
if let Some(tag) = tag_opt
208+
&& tag.eq_ignore_ascii_case("edge")
209+
{
210+
continue;
211211
}
212212
return (filter, Some((*img).clone()));
213213
}

src/dialogs/exportable_apps_dialog.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ impl ExportableAppsDialog {
195195
if binary_name_or_path.contains('/') {
196196
// For paths, we need to check on the host using a command
197197
// We'll use 'test -e' which returns 0 if the file exists
198-
let expanded_path = if binary_name_or_path.starts_with("~/") {
198+
let expanded_path = if let Some(stripped) = binary_name_or_path.strip_prefix("~/") {
199199
// Expand home on host - use $HOME variable
200-
format!("$HOME/{}", &binary_name_or_path[2..])
200+
format!("$HOME/{stripped}")
201201
} else {
202202
binary_name_or_path.to_string()
203203
};
@@ -352,12 +352,12 @@ impl ExportableAppsDialog {
352352

353353
if exists {
354354
// Show confirmation dialog
355+
let confirmation_body = gettext(
356+
"The binary already exists on your host system. Do you want to continue?",
357+
);
355358
let dialog = adw::AlertDialog::new(
356359
Some(&gettext("Binary Already Exists on Host")),
357-
Some(&format!(
358-
"{}",
359-
gettext("The binary already exists on your host system. Do you want to continue?"),
360-
)),
360+
Some(&confirmation_body),
361361
);
362362
dialog.add_response("cancel", &gettext("Cancel"));
363363
dialog.add_response("export", &gettext("Export Anyway"));

src/dialogs/preferences_dialog.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ impl PreferencesDialog {
304304
.string();
305305

306306
let dialog = adw::AlertDialog::builder()
307-
.heading(&gettext("Delete this terminal?"))
308-
.body(&gettext("This terminal will be removed from the terminal list. This action cannot be undone."))
307+
.heading(gettext("Delete this terminal?"))
308+
.body(gettext("This terminal will be removed from the terminal list. This action cannot be undone."))
309309
.close_response("cancel")
310310
.default_response("cancel")
311311
.build();
@@ -328,9 +328,9 @@ impl PreferencesDialog {
328328
{
329329
Ok(_) => {
330330
glib::MainContext::ref_thread_default().spawn_local(async move {
331-
if let Some(terminal_combo_row) =
332-
this.imp().terminal_combo_row.borrow().as_ref()
333-
{
331+
let terminal_combo_row =
332+
this.imp().terminal_combo_row.borrow().as_ref().cloned();
333+
if let Some(terminal_combo_row) = terminal_combo_row {
334334
terminal_combo_row.rebuild_terminals_list();
335335
terminal_combo_row.set_selected_by_name(
336336
&this

src/distrobox_downloader.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,18 @@ pub fn cleanup_old_bundled_versions() {
8888
Some(s) => s.to_string(),
8989
None => continue,
9090
};
91-
if name_str.starts_with("distrobox-") && name_str != current_dir_name {
92-
if entry.path().is_dir() {
93-
if let Err(e) = std::fs::remove_dir_all(entry.path()) {
94-
tracing::warn!(
95-
"Failed to remove old bundled version {:?}: {}",
96-
entry.path(),
97-
e
98-
);
99-
} else {
100-
tracing::info!("Removed old bundled version: {}", name_str);
101-
}
91+
if name_str.starts_with("distrobox-")
92+
&& name_str != current_dir_name
93+
&& entry.path().is_dir()
94+
{
95+
if let Err(e) = std::fs::remove_dir_all(entry.path()) {
96+
tracing::warn!(
97+
"Failed to remove old bundled version {:?}: {}",
98+
entry.path(),
99+
e
100+
);
101+
} else {
102+
tracing::info!("Removed old bundled version: {}", name_str);
102103
}
103104
}
104105
}

src/fakers/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ impl Command {
9090

9191
// removes the first occurrence of an arg by name and its value
9292
pub fn remove_flag_value_arg(&mut self, name: &str) -> &mut Command {
93-
self.args.iter().position(|x| x == name).map(|index| {
93+
if let Some(index) = self.args.iter().position(|x| x == name) {
9494
self.args.remove(index);
9595
self.args.remove(index); // same index, as the vector has shifted
96-
});
96+
}
9797
self
9898
}
9999
pub fn remove_flag_arg(&mut self, name: &str) -> &mut Command {

src/fakers/command_runner.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use futures::{
2020
io::{AsyncRead, AsyncWrite, Cursor},
2121
};
2222

23+
type ResponseFn = Rc<dyn Fn() -> Result<String, io::Error>>;
24+
type ResponseMap = HashMap<Vec<String>, ResponseFn>;
25+
2326
#[derive(Debug, Clone)]
2427
pub enum CommandRunnerEvent {
2528
Spawned(usize, Command),
@@ -178,7 +181,7 @@ impl InnerCommandRunner for RealCommandRunner {
178181

179182
#[derive(Default, Clone)]
180183
pub struct NullCommandRunnerBuilder {
181-
responses: HashMap<Vec<String>, Rc<dyn Fn() -> Result<String, io::Error>>>,
184+
responses: ResponseMap,
182185
#[allow(dead_code)]
183186
fallback_exit_status: ExitStatus,
184187
}
@@ -220,7 +223,7 @@ impl NullCommandRunnerBuilder {
220223

221224
#[derive(Default, Clone)]
222225
pub struct NullCommandRunner {
223-
responses: HashMap<Vec<String>, Rc<dyn Fn() -> Result<String, io::Error>>>,
226+
responses: ResponseMap,
224227
#[allow(dead_code)]
225228
fallback_exit_status: ExitStatus,
226229
}

0 commit comments

Comments
 (0)