@@ -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 ,
@@ -414,23 +417,21 @@ pub(crate) fn wait_for_parent() -> anyhow::Result<()> {
414417 return Err ( err) . context ( CliError :: WindowsUninstallMadness ) ;
415418 }
416419
417- let snapshot = scopeguard:: guard ( snapshot, |h| {
418- let _ = CloseHandle ( h) ;
419- } ) ;
420+ let snapshot = OwnedHandle :: from_raw_handle ( snapshot) ;
420421
421422 let mut entry: PROCESSENTRY32 = mem:: zeroed ( ) ;
422423 entry. dwSize = size_of :: < PROCESSENTRY32 > ( ) as u32 ;
423424
424425 // Iterate over system processes looking for ours
425- let success = Process32First ( * snapshot, & mut entry) ;
426+ let success = Process32First ( snapshot. as_raw_handle ( ) , & mut entry) ;
426427 if success == 0 {
427428 let err = io:: Error :: last_os_error ( ) ;
428429 return Err ( err) . context ( CliError :: WindowsUninstallMadness ) ;
429430 }
430431
431432 let this_pid = GetCurrentProcessId ( ) ;
432433 while entry. th32ProcessID != this_pid {
433- let success = Process32Next ( * snapshot, & mut entry) ;
434+ let success = Process32Next ( snapshot. as_raw_handle ( ) , & mut entry) ;
434435 if success == 0 {
435436 let err = io:: Error :: last_os_error ( ) ;
436437 return Err ( err) . context ( CliError :: WindowsUninstallMadness ) ;
@@ -449,12 +450,10 @@ pub(crate) fn wait_for_parent() -> anyhow::Result<()> {
449450 return Ok ( ( ) ) ;
450451 }
451452
452- let parent = scopeguard:: guard ( parent, |h| {
453- let _ = CloseHandle ( h) ;
454- } ) ;
453+ let parent = OwnedHandle :: from_raw_handle ( parent) ;
455454
456455 // Wait for our parent to exit
457- let res = WaitForSingleObject ( * parent, INFINITE ) ;
456+ let res = WaitForSingleObject ( parent. as_raw_handle ( ) , INFINITE ) ;
458457
459458 if res != WAIT_OBJECT_0 {
460459 let err = io:: Error :: last_os_error ( ) ;
0 commit comments