@@ -6,7 +6,10 @@ use std::{
66 fs:: OpenOptions ,
77 io:: { self , Write } ,
88 mem,
9- os:: windows:: fs:: OpenOptionsExt ,
9+ os:: windows:: {
10+ fs:: OpenOptionsExt ,
11+ io:: { AsRawHandle , FromRawHandle , OwnedHandle } ,
12+ } ,
1013 path:: { Path , PathBuf } ,
1114 process:: { Command , Stdio } ,
1215 ptr, thread,
@@ -23,8 +26,8 @@ use windows_registry::{CURRENT_USER, HSTRING, Key};
2326use windows_result:: WIN32_ERROR ;
2427use windows_sys:: Win32 :: {
2528 Foundation :: {
26- CloseHandle , ERROR_FILE_NOT_FOUND , ERROR_INVALID_DATA , INVALID_HANDLE_VALUE , LPARAM ,
27- WAIT_OBJECT_0 , WPARAM ,
29+ ERROR_FILE_NOT_FOUND , ERROR_INVALID_DATA , INVALID_HANDLE_VALUE , LPARAM , WAIT_OBJECT_0 ,
30+ WPARAM ,
2831 } ,
2932 Storage :: FileSystem :: {
3033 FILE_FLAG_DELETE_ON_CLOSE , FILE_SHARE_DELETE , FILE_SHARE_READ , SYNCHRONIZE ,
@@ -415,23 +418,21 @@ pub(crate) fn wait_for_parent() -> anyhow::Result<()> {
415418 return Err ( err) . context ( CliError :: WindowsUninstallMadness ) ;
416419 }
417420
418- let snapshot = scopeguard:: guard ( snapshot, |h| {
419- let _ = CloseHandle ( h) ;
420- } ) ;
421+ let snapshot = OwnedHandle :: from_raw_handle ( snapshot) ;
421422
422423 let mut entry: PROCESSENTRY32 = mem:: zeroed ( ) ;
423424 entry. dwSize = size_of :: < PROCESSENTRY32 > ( ) as u32 ;
424425
425426 // Iterate over system processes looking for ours
426- let success = Process32First ( * snapshot, & mut entry) ;
427+ let success = Process32First ( snapshot. as_raw_handle ( ) , & mut entry) ;
427428 if success == 0 {
428429 let err = io:: Error :: last_os_error ( ) ;
429430 return Err ( err) . context ( CliError :: WindowsUninstallMadness ) ;
430431 }
431432
432433 let this_pid = GetCurrentProcessId ( ) ;
433434 while entry. th32ProcessID != this_pid {
434- let success = Process32Next ( * snapshot, & mut entry) ;
435+ let success = Process32Next ( snapshot. as_raw_handle ( ) , & mut entry) ;
435436 if success == 0 {
436437 let err = io:: Error :: last_os_error ( ) ;
437438 return Err ( err) . context ( CliError :: WindowsUninstallMadness ) ;
@@ -450,12 +451,10 @@ pub(crate) fn wait_for_parent() -> anyhow::Result<()> {
450451 return Ok ( ( ) ) ;
451452 }
452453
453- let parent = scopeguard:: guard ( parent, |h| {
454- let _ = CloseHandle ( h) ;
455- } ) ;
454+ let parent = OwnedHandle :: from_raw_handle ( parent) ;
456455
457456 // Wait for our parent to exit
458- let res = WaitForSingleObject ( * parent, INFINITE ) ;
457+ let res = WaitForSingleObject ( parent. as_raw_handle ( ) , INFINITE ) ;
459458
460459 if res != WAIT_OBJECT_0 {
461460 let err = io:: Error :: last_os_error ( ) ;
0 commit comments