Skip to content

Commit cec0ce5

Browse files
committed
fix clippy warnings
1 parent d609804 commit cec0ce5

4 files changed

Lines changed: 26 additions & 34 deletions

File tree

src/lib/greenboot.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub fn run_diagnostics(skipped: Vec<String>) -> Result<Vec<String>> {
2121

2222
// Run required checks
2323
for path in GREENBOOT_INSTALL_PATHS {
24-
let greenboot_required_path = format!("{}/check/required.d/", path);
24+
let greenboot_required_path = format!("{path}/check/required.d/");
2525
if !Path::new(&greenboot_required_path).is_dir() {
26-
log::warn!("skipping test as {} is not a dir", greenboot_required_path);
26+
log::warn!("skipping test as {greenboot_required_path} is not a dir");
2727
continue;
2828
}
2929
path_exists = true;
@@ -43,7 +43,7 @@ pub fn run_diagnostics(skipped: Vec<String>) -> Result<Vec<String>> {
4343

4444
// Run wanted checks
4545
for path in GREENBOOT_INSTALL_PATHS {
46-
let greenboot_wanted_path = format!("{}/check/wanted.d/", path);
46+
let greenboot_wanted_path = format!("{path}/check/wanted.d/");
4747
let result = run_scripts("wanted", &greenboot_wanted_path, Some(&skipped));
4848
all_skipped.extend(result.skipped);
4949

@@ -61,8 +61,7 @@ pub fn run_diagnostics(skipped: Vec<String>) -> Result<Vec<String>> {
6161

6262
if !missing_disabled.is_empty() {
6363
log::warn!(
64-
"The following disabled scripts were not found in any directory: {:?}",
65-
missing_disabled
64+
"The following disabled scripts were not found in any directory: {missing_disabled:?}"
6665
);
6766
}
6867

@@ -74,7 +73,7 @@ pub fn run_red() -> Vec<Box<dyn Error>> {
7473
let mut errors = Vec::new();
7574

7675
for path in GREENBOOT_INSTALL_PATHS {
77-
let red_path = format!("{}/red.d/", path);
76+
let red_path = format!("{path}/red.d/");
7877
let result = run_scripts("red", &red_path, None); // Pass None for disabled scripts
7978
errors.extend(result.errors);
8079
}
@@ -87,7 +86,7 @@ pub fn run_green() -> Vec<Box<dyn Error>> {
8786
let mut errors = Vec::new();
8887

8988
for path in GREENBOOT_INSTALL_PATHS {
90-
let green_path = format!("{}/green.d/", path);
89+
let green_path = format!("{path}/green.d/");
9190
let result = run_scripts("green", &green_path, None); // Pass None for disabled scripts
9291
errors.extend(result.errors);
9392
}
@@ -106,7 +105,7 @@ fn run_scripts(name: &str, path: &str, disabled_scripts: Option<&[String]>) -> S
106105
skipped: Vec::new(),
107106
};
108107

109-
let entries = match glob(&format!("{}*", path)) {
108+
let entries = match glob(&format!("{path}*")) {
110109
Ok(e) => {
111110
let valid: Vec<_> = e
112111
.filter_map(Result::ok)
@@ -139,7 +138,7 @@ fn run_scripts(name: &str, path: &str, disabled_scripts: Option<&[String]>) -> S
139138
// Check if script/binary should be skipped
140139
if let Some(disabled) = disabled_scripts {
141140
if disabled.contains(&file_name.to_string()) {
142-
log::info!("Skipping disabled script: {}", file_name);
141+
log::info!("Skipping disabled script: {file_name}");
143142
result.skipped.push(file_name.to_string());
144143
continue;
145144
}

src/lib/handler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ pub fn handle_rollback() -> Result<()> {
6161
log::info!("Greenboot will now attempt to rollback to a previous deployment.");
6262
if let Some(deployment_cmd) = detect_os_deployment() {
6363
log::info!(
64-
"Deployment manager '{}' detected, attempting rollback.",
65-
deployment_cmd
64+
"Deployment manager '{deployment_cmd}' detected, attempting rollback."
6665
);
6766
let status = Command::new(deployment_cmd)
6867
.arg("rollback")
6968
.status()
70-
.context(format!("Failed to execute '{} rollback'", deployment_cmd))?;
69+
.context(format!("Failed to execute '{deployment_cmd} rollback'"))?;
7170

7271
if !status.success() {
7372
bail!(

src/lib/mount.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ pub fn remount_boot_ro(mounts_path: &Path) -> Result<(), MountError> {
4242
} else {
4343
let error_message = String::from_utf8_lossy(&output.stderr);
4444
warn!(
45-
"Failed to remount /boot as RO using shell: {}",
46-
error_message
45+
"Failed to remount /boot as RO using shell: {error_message}"
4746
);
4847
Err(MountError::RemountFailed(error_message.to_string()))
4948
}
5049
}
5150
Err(e) => {
52-
warn!("Failed to execute mount command: {}", e);
51+
warn!("Failed to execute mount command: {e}");
5352
Err(MountError::RemountFailed(format!(
54-
"Failed to execute mount: {}",
55-
e
53+
"Failed to execute mount: {e}"
5654
)))
5755
}
5856
}
@@ -82,17 +80,15 @@ pub fn remount_boot_rw(mounts_path: &Path) -> Result<(), MountError> {
8280
} else {
8381
let error_message = String::from_utf8_lossy(&output.stderr);
8482
warn!(
85-
"Failed to remount /boot as RW using shell: {}",
86-
error_message
83+
"Failed to remount /boot as RW using shell: {error_message}"
8784
);
8885
Err(MountError::RemountFailed(error_message.to_string()))
8986
}
9087
}
9188
Err(e) => {
92-
warn!("Failed to execute mount command: {}", e);
89+
warn!("Failed to execute mount command: {e}");
9390
Err(MountError::RemountFailed(format!(
94-
"Failed to execute mount: {}",
95-
e
91+
"Failed to execute mount: {e}"
9692
)))
9793
}
9894
}

src/main.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn check_previous_rollback() -> Result<bool> {
135135
// Check for specific success indicators
136136
let success = journal_output.contains("Rollback successful");
137137

138-
log::debug!("Rollback detection result: {}", success);
138+
log::debug!("Rollback detection result: {success}");
139139
Ok(success)
140140
}
141141

@@ -168,8 +168,7 @@ fn health_check() -> Result<()> {
168168
}
169169
Err(e) => {
170170
log::warn!(
171-
"Failed to check previous rollback status: {}. Defaulting to false.",
172-
e
171+
"Failed to check previous rollback status: {e}. Defaulting to false."
173172
);
174173
false
175174
}
@@ -194,7 +193,7 @@ fn health_check() -> Result<()> {
194193
"Greenboot healthcheck passed - status is GREEN",
195194
previous_rollback,
196195
)?)
197-
.unwrap_or_else(|e| log::error!("cannot set motd: {}", e));
196+
.unwrap_or_else(|e| log::error!("cannot set motd: {e}"));
198197
set_boot_status(true, GRUB_PATH, MOUNT_INFO_PATH)?;
199198
Ok(())
200199
}
@@ -205,18 +204,18 @@ fn health_check() -> Result<()> {
205204
"Greenboot healthcheck failed - status is RED",
206205
previous_rollback,
207206
)?)
208-
.unwrap_or_else(|e| log::error!("cannot set motd: {}", e));
207+
.unwrap_or_else(|e| log::error!("cannot set motd: {e}"));
209208
let errors = run_red();
210209
if !errors.is_empty() {
211210
log::error!("There is a problem with red script runner");
212211
errors.iter().for_each(|e| log::error!("{e}"));
213212
}
214213

215214
set_boot_status(false, GRUB_PATH, MOUNT_INFO_PATH)
216-
.unwrap_or_else(|e| log::error!("cannot set boot_status: {}", e));
215+
.unwrap_or_else(|e| log::error!("cannot set boot_status: {e}"));
217216
set_boot_counter(config.max_reboot, GRUB_PATH, MOUNT_INFO_PATH)
218-
.unwrap_or_else(|e| log::error!("cannot set boot_counter: {}", e));
219-
handle_reboot(false).unwrap_or_else(|e| log::error!("cannot reboot: {}", e));
217+
.unwrap_or_else(|e| log::error!("cannot set boot_counter: {e}"));
218+
handle_reboot(false).unwrap_or_else(|e| log::error!("cannot reboot: {e}"));
220219
bail!("greenboot healthcheck failed")
221220
}
222221
}
@@ -239,7 +238,7 @@ fn trigger_rollback() -> Result<()> {
239238
// This function parses a string expected in bash-array format like
240239
// `( "item1" "item2" ... )` into a Vec<String>.
241240
fn parse_bash_array_string(raw_str: &str) -> Vec<String> {
242-
log::debug!("Attempting to parse raw bash-array string: '{}'", raw_str);
241+
log::debug!("Attempting to parse raw bash-array string: '{raw_str}'");
243242

244243
if raw_str.starts_with('(') && raw_str.ends_with(')') {
245244
// Remove the outer parentheses
@@ -252,14 +251,13 @@ fn parse_bash_array_string(raw_str: &str) -> Vec<String> {
252251
.filter(|s| !s.is_empty())
253252
.collect();
254253

255-
log::debug!("Parsed list from bash-array string: {:?}", parsed_list);
254+
log::debug!("Parsed list from bash-array string: {parsed_list:?}");
256255
parsed_list
257256
} else if !raw_str.trim().is_empty() {
258257
// If the string is not empty but doesn't match the expected format,
259258
// log a warning and return an empty list.
260259
log::warn!(
261-
"String ('{}') is not in the expected bash-array format '( \"item1\" ... )'. Treating as empty list.",
262-
raw_str
260+
"String ('{raw_str}') is not in the expected bash-array format '( \"item1\" ... )'. Treating as empty list."
263261
);
264262
vec![]
265263
} else {

0 commit comments

Comments
 (0)