@@ -16,8 +16,8 @@ use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
1616use wmi:: { COMLibrary , WMIConnection , WMIError } ;
1717
1818use super :: {
19- create_dump_file, Dumper , IntoModuleReport , ModuleError , ModuleMetadata , ModuleRunInfo ,
20- ModuleStrategy , ToUninstall , UninstallError ,
19+ create_dump_file, Dumper , IntoModuleReport , IntoUninstallReport , ModuleError , ModuleMetadata ,
20+ ModuleRunInfo , ModuleStrategy , ToUninstall , UninstallError ,
2121} ;
2222use crate :: {
2323 cleanup_modules:: get_path_to_dump,
@@ -99,21 +99,18 @@ impl ModuleStrategy for DriverPackageCleanupModule {
9999 use UninstallMethod :: * ;
100100
101101 match & to_uninstall. uninstall_method {
102- Normal => {
103- run_uninstall_method ( uninstall_normal, state, & object, to_uninstall) . await
104- } ,
102+ Normal => run_uninstall_method ( uninstall_normal, state, & object, to_uninstall) . await ,
105103 Deferred => {
106104 run_uninstall_method ( uninstall_deferred, state, & object, to_uninstall) . await
107105 }
108106 RegistryOnly => {
109- uninstall_registry_only ( object, to_uninstall)
110- . attach_printable_lazy ( || {
111- format ! (
112- "failed to open uninstall key for driver package '{}'" ,
113- to_uninstall. friendly_name
114- )
115- } )
116- } ,
107+ uninstall_registry_only ( object, to_uninstall) . attach_printable_lazy ( || {
108+ format ! (
109+ "failed to open uninstall key for driver package '{}'" ,
110+ to_uninstall. friendly_name
111+ )
112+ } )
113+ }
117114 }
118115 }
119116
@@ -124,7 +121,7 @@ impl ModuleStrategy for DriverPackageCleanupModule {
124121
125122fn uninstall_registry_only (
126123 object : DriverPackage ,
127- _to_uninstall : & DriverPackageToUninstall ,
124+ to_uninstall : & DriverPackageToUninstall ,
128125) -> Result < ( ) , UninstallError > {
129126 let key_path = Path :: new ( object. key_name ( ) ) ;
130127 let key_parent = key_path. parent ( ) . unwrap ( ) ;
@@ -135,13 +132,13 @@ fn uninstall_registry_only(
135132 . open_subkey_with_flags ( key_parent, flags)
136133 . into_report ( )
137134 . attach_printable_lazy ( || key_parent. to_string_lossy ( ) . to_string ( ) )
138- . change_context ( UninstallError :: UninstallFailed ) ?;
135+ . into_uninstall_report ( to_uninstall ) ?;
139136
140137 uninstall_key
141138 . delete_subkey_all ( key_name)
142139 . into_report ( )
143140 . attach_printable_lazy ( || key_path. to_string_lossy ( ) . to_string ( ) )
144- . change_context ( UninstallError :: UninstallFailed )
141+ . into_uninstall_report ( to_uninstall )
145142}
146143
147144#[ derive( Default ) ]
@@ -226,40 +223,40 @@ where
226223async fn uninstall_normal (
227224 _state : & State ,
228225 object : & DriverPackage ,
229- _to_uninstall : & DriverPackageToUninstall ,
226+ to_uninstall : & DriverPackageToUninstall ,
230227 _ct : CancellationToken ,
231228) -> Result < ( ) , UninstallError > {
232229 let uninstall_string = object. uninstall_string ( ) . unwrap ( ) ;
233230 let child_process = match to_command ( uninstall_string) . spawn ( ) {
234231 Ok ( child) => child,
235232 Err ( err) => match err. kind ( ) {
236- ErrorKind :: NotFound => bail ! ( UninstallError :: AlreadyUninstalled ) ,
233+ ErrorKind :: NotFound => bail ! ( UninstallError :: uninstalled ( to_uninstall ) ) ,
237234 _ => {
238235 return Err ( err)
239236 . into_report ( )
240- . change_context ( UninstallError :: UninstallFailed )
241237 . attach_printable_lazy ( || {
242238 format ! ( "failed to launch uninstaller: {}" , uninstall_string)
243239 } )
240+ . into_uninstall_report ( to_uninstall)
244241 }
245242 } ,
246243 } ;
247244
248245 wait_for_process_async ( child_process)
249246 . await
250247 . into_report ( )
251- . change_context ( UninstallError :: UninstallFailed )
252248 . attach_printable_lazy ( || {
253249 format ! ( "failed to wait on child process, exe: {}" , uninstall_string)
254- } ) ?;
250+ } )
251+ . into_uninstall_report ( to_uninstall) ?;
255252
256253 Ok ( ( ) )
257254}
258255
259256async fn uninstall_deferred (
260257 _state : & State ,
261258 object : & DriverPackage ,
262- _to_uninstall : & DriverPackageToUninstall ,
259+ to_uninstall : & DriverPackageToUninstall ,
263260 _ct : CancellationToken ,
264261) -> Result < ( ) , UninstallError > {
265262 let uninstall_string = object. uninstall_string ( ) . unwrap ( ) ;
@@ -274,14 +271,14 @@ async fn uninstall_deferred(
274271 let child = match command. spawn ( ) {
275272 Ok ( child) => child,
276273 Err ( err) => match err. kind ( ) {
277- ErrorKind :: NotFound => bail ! ( UninstallError :: AlreadyUninstalled ) ,
274+ ErrorKind :: NotFound => bail ! ( UninstallError :: uninstalled ( to_uninstall ) ) ,
278275 _ => {
279276 return Err ( err)
280277 . into_report ( )
281- . change_context ( UninstallError :: UninstallFailed )
282278 . attach_printable_lazy ( || {
283279 format ! ( "failed to launch uninstaller: {}" , uninstall_string)
284280 } )
281+ . into_uninstall_report ( to_uninstall)
285282 }
286283 } ,
287284 } ;
@@ -314,22 +311,22 @@ async fn uninstall_deferred(
314311 ( Err ( err) , _) => {
315312 return Err ( err)
316313 . into_report ( )
317- . change_context ( UninstallError :: UninstallFailed )
318314 . attach_printable ( "failed to wait for main uninstaller process" )
315+ . into_uninstall_report ( to_uninstall)
319316 }
320317 ( _, Err ( err) ) => {
321318 return Err ( err)
322- . change_context ( UninstallError :: UninstallFailed )
323319 . attach_printable ( "failed to wait for uninstaller's delegated process" )
320+ . into_uninstall_report ( to_uninstall)
324321 }
325322 }
326323 ct. cancel ( ) ;
327324 } else {
328325 wait_for_process_async ( child)
329326 . await
330327 . into_report ( )
331- . change_context ( UninstallError :: UninstallFailed )
332- . attach_printable ( "failed to wait for main uninstaller process" ) ?;
328+ . attach_printable ( "failed to wait for main uninstaller process" )
329+ . into_uninstall_report ( to_uninstall ) ?;
333330 }
334331
335332 Ok ( ( ) )
0 commit comments