Skip to content

Commit c4e2b6e

Browse files
(MAINT) Fix clippy for WindowsUpdate
1 parent 3c4e87e commit c4e2b6e

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

resources/WindowsUpdate/src/windows_update/export.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn handle_export(input: &str) -> Result<String> {
3333
}
3434
} else {
3535
serde_json::from_str(input)
36-
.map_err(|e| Error::new(E_INVALIDARG.into(), t!("export.failedParseInput", err = e.to_string()).to_string()))?
36+
.map_err(|e| Error::new(E_INVALIDARG, t!("export.failedParseInput", err = e.to_string())))?
3737
};
3838

3939
let filters = &update_list.updates;
@@ -120,16 +120,14 @@ pub fn handle_export(input: &str) -> Result<String> {
120120
}
121121

122122
// Filter by KB article IDs (match if any KB ID in the filter is present)
123-
if let Some(kb_filter) = &filter.kb_article_ids {
124-
if !kb_filter.is_empty() {
125-
if let Some(ref kb_article_ids) = update_info.kb_article_ids {
126-
let kb_matches = kb_filter.iter().any(|filter_kb| {
127-
kb_article_ids.iter().any(|update_kb| update_kb.eq_ignore_ascii_case(filter_kb))
128-
});
129-
matches = matches && kb_matches;
130-
} else {
131-
matches = false;
132-
}
123+
if let Some(kb_filter) = &filter.kb_article_ids && !kb_filter.is_empty() {
124+
if let Some(ref kb_article_ids) = update_info.kb_article_ids {
125+
let kb_matches = kb_filter.iter().any(|filter_kb| {
126+
kb_article_ids.iter().any(|update_kb| update_kb.eq_ignore_ascii_case(filter_kb))
127+
});
128+
matches = matches && kb_matches;
129+
} else {
130+
matches = false;
133131
}
134132
}
135133

@@ -148,8 +146,8 @@ pub fn handle_export(input: &str) -> Result<String> {
148146
}
149147

150148
// Filter by security bulletin IDs (match if any bulletin ID in the filter is present)
151-
if let Some(bulletin_filter) = &filter.security_bulletin_ids {
152-
if !bulletin_filter.is_empty() {
149+
if let Some(bulletin_filter) = &filter.security_bulletin_ids
150+
&& !bulletin_filter.is_empty() {
153151
if let Some(ref security_bulletin_ids) = update_info.security_bulletin_ids {
154152
let bulletin_matches = bulletin_filter.iter().any(|filter_bulletin| {
155153
security_bulletin_ids.iter().any(|update_bulletin| update_bulletin.eq_ignore_ascii_case(filter_bulletin))
@@ -159,7 +157,6 @@ pub fn handle_export(input: &str) -> Result<String> {
159157
matches = false;
160158
}
161159
}
162-
}
163160

164161
// Filter by update type
165162
if let Some(type_filter) = &filter.update_type {
@@ -230,7 +227,7 @@ pub fn handle_export(input: &str) -> Result<String> {
230227
// Emit JSON error to stderr
231228
eprintln!("{{\"error\":\"{}\"}}", error_msg);
232229

233-
return Err(Error::new(E_FAIL.into(), error_msg));
230+
return Err(Error::new(E_FAIL, error_msg));
234231
}
235232
}
236233
}
@@ -252,7 +249,7 @@ pub fn handle_export(input: &str) -> Result<String> {
252249
updates
253250
};
254251
serde_json::to_string(&result)
255-
.map_err(|e| Error::new(E_FAIL.into(), t!("export.failedSerializeOutput", err = e.to_string()).to_string()))
252+
.map_err(|e| Error::new(E_FAIL, t!("export.failedSerializeOutput", err = e.to_string())))
256253
}
257254
Err(e) => Err(e),
258255
}
@@ -303,15 +300,13 @@ fn matches_wildcard(text: &str, pattern: &str) -> bool {
303300
}
304301
}
305302
}
306-
303+
307304
// For the last part, check if it should be at the end
308-
if !ends_with_wildcard && !parts.is_empty() {
309-
if let Some(last_part) = parts.last() {
310-
if !last_part.is_empty() && !text_lower.ends_with(last_part) {
311-
return false;
312-
}
305+
if !ends_with_wildcard && !parts.is_empty()
306+
&& let Some(last_part) = parts.last()
307+
&& !last_part.is_empty() && !text_lower.ends_with(last_part) {
308+
return false;
313309
}
314-
}
315-
310+
316311
true
317312
}

resources/WindowsUpdate/src/windows_update/get.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use crate::windows_update::types::{UpdateList, extract_update_info};
1414
pub fn handle_get(input: &str) -> Result<String> {
1515
// Parse input as UpdateList
1616
let update_list: UpdateList = serde_json::from_str(input)
17-
.map_err(|e| Error::new(E_INVALIDARG.into(), t!("get.failedParseInput", err = e.to_string()).to_string()))?;
17+
.map_err(|e| Error::new(E_INVALIDARG, t!("get.failedParseInput", err = e.to_string())))?;
1818

1919
if update_list.updates.is_empty() {
20-
return Err(Error::new(E_INVALIDARG.into(), t!("get.updatesArrayEmpty").to_string()));
20+
return Err(Error::new(E_INVALIDARG, t!("get.updatesArrayEmpty")));
2121
}
2222

2323
// Initialize COM
@@ -54,7 +54,7 @@ pub fn handle_get(input: &str) -> Result<String> {
5454
&& update_input.is_installed.is_none()
5555
&& update_input.update_type.is_none()
5656
&& update_input.msrc_severity.is_none() {
57-
return Err(Error::new(E_INVALIDARG.into(), t!("get.atLeastOneCriterionRequired").to_string()));
57+
return Err(Error::new(E_INVALIDARG, t!("get.atLeastOneCriterionRequired")));
5858
}
5959

6060
// Find the update matching ALL provided criteria (logical AND)
@@ -168,7 +168,7 @@ pub fn handle_get(input: &str) -> Result<String> {
168168
};
169169

170170
eprintln!("{{\"error\":\"{}\"}}", error_msg);
171-
return Err(Error::new(E_INVALIDARG.into(), error_msg));
171+
return Err(Error::new(E_INVALIDARG, error_msg));
172172
}
173173

174174
// Get the first (and should be only) match
@@ -206,7 +206,7 @@ pub fn handle_get(input: &str) -> Result<String> {
206206
// Emit JSON error to stderr
207207
eprintln!("{{\"error\":\"{}\"}}", error_msg);
208208

209-
return Err(Error::new(E_FAIL.into(), error_msg));
209+
return Err(Error::new(E_FAIL, error_msg));
210210
}
211211
}
212212

@@ -227,7 +227,7 @@ pub fn handle_get(input: &str) -> Result<String> {
227227
updates
228228
};
229229
serde_json::to_string(&result)
230-
.map_err(|e| Error::new(E_FAIL.into(), t!("get.failedSerializeOutput", err = e.to_string()).to_string()))
230+
.map_err(|e| Error::new(E_FAIL, t!("get.failedSerializeOutput", err = e.to_string())))
231231
}
232232
Err(e) => Err(e),
233233
}

resources/WindowsUpdate/src/windows_update/set.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ fn get_computer_name() -> String {
2020
pub fn handle_set(input: &str) -> Result<String> {
2121
// Parse input as UpdateList
2222
let update_list: UpdateList = serde_json::from_str(input)
23-
.map_err(|e| Error::new(E_INVALIDARG.into(), t!("set.failedParseInput", err = e.to_string()).to_string()))?;
23+
.map_err(|e| Error::new(E_INVALIDARG, t!("set.failedParseInput", err = e.to_string())))?;
2424

2525
if update_list.updates.is_empty() {
26-
return Err(Error::new(E_INVALIDARG.into(), t!("set.updatesArrayEmpty").to_string()));
26+
return Err(Error::new(E_INVALIDARG, t!("set.updatesArrayEmpty")));
2727
}
2828

2929
// Initialize COM
@@ -60,7 +60,7 @@ pub fn handle_set(input: &str) -> Result<String> {
6060
&& update_input.is_installed.is_none()
6161
&& update_input.update_type.is_none()
6262
&& update_input.msrc_severity.is_none() {
63-
return Err(Error::new(E_INVALIDARG.into(), t!("set.atLeastOneCriterionRequired").to_string()));
63+
return Err(Error::new(E_INVALIDARG, t!("set.atLeastOneCriterionRequired")));
6464
}
6565

6666
// Find the update matching ALL provided criteria (logical AND)
@@ -167,7 +167,7 @@ pub fn handle_set(input: &str) -> Result<String> {
167167
t!("set.criteriaMatchedMultipleUpdates", count = matching_updates.len()).to_string()
168168
};
169169
eprintln!("{{\"error\":\"{}\"}}", error_msg);
170-
return Err(Error::new(E_INVALIDARG.into(), error_msg));
170+
return Err(Error::new(E_INVALIDARG, error_msg));
171171
}
172172

173173
// Get the first (and should be only) match
@@ -205,7 +205,7 @@ pub fn handle_set(input: &str) -> Result<String> {
205205
// Emit JSON error to stderr
206206
eprintln!("{{\"error\":\"{}\"}}", error_msg);
207207

208-
return Err(Error::new(E_FAIL.into(), error_msg));
208+
return Err(Error::new(E_FAIL, error_msg));
209209
}
210210
}
211211

@@ -238,7 +238,7 @@ pub fn handle_set(input: &str) -> Result<String> {
238238
// Check if download was successful (orcSucceeded = 2)
239239
if result_code != OperationResultCode(2) {
240240
let hresult = download_result.HResult()?;
241-
return Err(Error::new(HRESULT(hresult).into(), t!("set.failedDownloadUpdate", code = result_code.0).to_string()));
241+
return Err(Error::new(HRESULT(hresult), t!("set.failedDownloadUpdate", code = result_code.0)));
242242
}
243243
}
244244

@@ -252,17 +252,15 @@ pub fn handle_set(input: &str) -> Result<String> {
252252
// Check if installation was successful (orcSucceeded = 2)
253253
if result_code != OperationResultCode(2) {
254254
let hresult = install_result.HResult()?;
255-
return Err(Error::new(HRESULT(hresult).into(), t!("set.failedInstallUpdate", code = result_code.0).to_string()));
255+
return Err(Error::new(HRESULT(hresult), t!("set.failedInstallUpdate", code = result_code.0)));
256256
}
257257

258258
// Check if installation result indicates a reboot is required
259-
if !reboot_required {
260-
if let Ok(reboot_req) = install_result.RebootRequired() {
261-
if reboot_req.as_bool() {
262-
reboot_required = true;
263-
}
259+
if !reboot_required
260+
&& let Ok(reboot_req) = install_result.RebootRequired()
261+
&& reboot_req.as_bool() {
262+
reboot_required = true;
264263
}
265-
}
266264

267265
// Get full details now that it's installed
268266
extract_update_info(&update)?
@@ -298,7 +296,7 @@ pub fn handle_set(input: &str) -> Result<String> {
298296
updates
299297
};
300298
serde_json::to_string(&results)
301-
.map_err(|e| Error::new(E_FAIL.into(), t!("set.failedSerializeOutput", err = e.to_string()).to_string()))
299+
.map_err(|e| Error::new(E_FAIL, t!("set.failedSerializeOutput", err = e.to_string())))
302300
}
303301
Err(e) => Err(e),
304302
}

0 commit comments

Comments
 (0)