Skip to content

Commit 3c4e87e

Browse files
(MAINT) Fix clippy for windows_service
1 parent 97737b2 commit 3c4e87e

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

resources/windows_service/src/service.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ unsafe fn read_service_state(
9292
let sizing_result = unsafe {
9393
QueryServiceConfigW(service_handle, None, 0, &mut bytes_needed)
9494
};
95-
if let Err(e) = sizing_result {
96-
if e.code() != ERROR_INSUFFICIENT_BUFFER.to_hresult() {
97-
return Err(t!("get.queryConfigFailed", error = e.to_string()).to_string().into());
98-
}
95+
if let Err(e) = sizing_result && e.code() != ERROR_INSUFFICIENT_BUFFER.to_hresult() {
96+
return Err(t!("get.queryConfigFailed", error = e.to_string()).to_string().into());
9997
}
10098
if bytes_needed == 0 {
10199
return Err(t!("get.queryConfigFailed", error = "buffer size is 0").to_string().into());
@@ -223,8 +221,8 @@ pub fn get_service(input: &WindowsService) -> Result<WindowsService, ServiceErro
223221
let svc = unsafe { read_service_state(service_handle.0, &service_key_name) }?;
224222

225223
// If both name and display_name were provided, verify they match
226-
if input.name.is_some() && input.display_name.is_some() {
227-
let expected_dn = input.display_name.as_ref().unwrap();
224+
if input.name.is_some() && let Some(expected_dn) = input.display_name.as_ref() {
225+
// let expected_dn = input.display_name.as_ref().unwrap();
228226
let actual_dn = svc.display_name.as_deref().unwrap_or("");
229227
if !actual_dn.eq_ignore_ascii_case(expected_dn) {
230228
return Err(
@@ -412,21 +410,17 @@ pub fn export_services(filter: Option<&WindowsService>) -> Result<Vec<WindowsSer
412410

413411
for (service_name, current_state) in &services {
414412
// Quick reject based on status before opening the service handle
415-
if let Some(expected_state) = status_filter_dw {
416-
if *current_state != expected_state {
417-
continue;
418-
}
413+
if let Some(expected_state) = status_filter_dw && *current_state != expected_state {
414+
continue;
419415
}
420416

421417
let svc = match unsafe { get_service_details(scm.0, service_name) } {
422418
Ok(s) => s,
423419
Err(_) => continue, // skip services we can't query
424420
};
425421

426-
if let Some(f) = filter {
427-
if !matches_filter(&svc, f) {
428-
continue;
429-
}
422+
if let Some(f) = filter && !matches_filter(&svc, f) {
423+
continue;
430424
}
431425

432426
results.push(svc);
@@ -457,13 +451,11 @@ unsafe fn enumerate_services(scm: SC_HANDLE) -> Result<Vec<(String, SERVICE_STAT
457451
None,
458452
);
459453

460-
if let Err(e) = sizing_result {
461-
if e.code() != ERROR_MORE_DATA.to_hresult()
462-
&& e.code() != ERROR_INSUFFICIENT_BUFFER.to_hresult()
463-
{
454+
if let Err(e) = sizing_result
455+
&& e.code() != ERROR_MORE_DATA.to_hresult()
456+
&& e.code() != ERROR_INSUFFICIENT_BUFFER.to_hresult() {
464457
return Err(t!("export.enumServicesFailed", error = e.to_string()).to_string().into());
465458
}
466-
}
467459

468460
if bytes_needed == 0 {
469461
return Ok(Vec::new());
@@ -571,13 +563,12 @@ fn matches_wildcard(text: &str, pattern: &str) -> bool {
571563
}
572564
}
573565

574-
if !ends_with_wildcard {
575-
if let Some(last) = parts.last() {
576-
if !last.is_empty() && !text_lower.ends_with(last) {
577-
return false;
578-
}
566+
if !ends_with_wildcard
567+
&& let Some(last) = parts.last()
568+
&& !last.is_empty()
569+
&& !text_lower.ends_with(last) {
570+
return false;
579571
}
580-
}
581572

582573
true
583574
}
@@ -616,12 +607,10 @@ pub fn set_service(input: &WindowsService) -> Result<WindowsService, ServiceErro
616607
let name = input.name.as_deref()
617608
.ok_or_else(|| t!("set.nameRequired").to_string())?;
618609

619-
if let Some(ref account) = input.logon_account {
620-
if !is_builtin_service_account(account) {
621-
return Err(ServiceError::from(
622-
t!("set.unsupportedLogonAccount", account = account).to_string(),
623-
));
624-
}
610+
if let Some(ref account) = input.logon_account && !is_builtin_service_account(account) {
611+
return Err(ServiceError::from(
612+
t!("set.unsupportedLogonAccount", account = account).to_string(),
613+
));
625614
}
626615

627616
unsafe {

0 commit comments

Comments
 (0)