Skip to content

Commit 65f9340

Browse files
committed
fix: chop key into subkey and parent
Fixes "path not found" error when running RegistryOnly uninstallation
1 parent f6b07c5 commit 65f9340

1 file changed

Lines changed: 22 additions & 27 deletions

File tree

src/cleanup_modules/driver_package_cleanup.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,21 @@ impl ModuleStrategy for DriverPackageCleanupModule {
9999
use UninstallMethod::*;
100100

101101
match &to_uninstall.uninstall_method {
102-
Normal => run_uninstall_method(uninstall_normal, state, &object, to_uninstall).await,
102+
Normal => {
103+
run_uninstall_method(uninstall_normal, state, &object, to_uninstall).await
104+
},
103105
Deferred => {
104106
run_uninstall_method(uninstall_deferred, state, &object, to_uninstall).await
105107
}
106-
RegistryOnly => uninstall_registry_only(object, to_uninstall),
108+
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+
},
107117
}
108118
}
109119

@@ -114,39 +124,24 @@ impl ModuleStrategy for DriverPackageCleanupModule {
114124

115125
fn uninstall_registry_only(
116126
object: DriverPackage,
117-
to_uninstall: &DriverPackageToUninstall,
127+
_to_uninstall: &DriverPackageToUninstall,
118128
) -> Result<(), UninstallError> {
119-
let base_key_name = if object.x86() {
120-
"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
121-
} else {
122-
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
123-
};
124-
129+
let key_path = Path::new(object.key_name());
130+
let key_parent = key_path.parent().unwrap();
131+
let key_name = key_path.file_name().unwrap();
125132
let flags = winreg::enums::KEY_WRITE;
133+
126134
let uninstall_key = RegKey::predef(HKEY_LOCAL_MACHINE)
127-
.open_subkey_with_flags(base_key_name, flags)
135+
.open_subkey_with_flags(key_parent, flags)
128136
.into_report()
129-
.change_context(UninstallError::UninstallFailed)
130-
.attach_printable_lazy(|| {
131-
format!(
132-
"failed to open uninstall key for driver package '{}'",
133-
to_uninstall.friendly_name
134-
)
135-
})?;
137+
.attach_printable_lazy(|| key_parent.to_string_lossy().to_string())
138+
.change_context(UninstallError::UninstallFailed)?;
136139

137140
uninstall_key
138-
.delete_subkey_all(Path::new(object.key_name()))
141+
.delete_subkey_all(key_name)
139142
.into_report()
140-
.attach_printable_lazy(|| {
141-
object.key_name().to_string()
142-
})
143+
.attach_printable_lazy(|| key_path.to_string_lossy().to_string())
143144
.change_context(UninstallError::UninstallFailed)
144-
.attach_printable_lazy(|| {
145-
format!(
146-
"failed to delete uninstall key for driver package '{}'",
147-
to_uninstall.friendly_name
148-
)
149-
})
150145
}
151146

152147
#[derive(Default)]

0 commit comments

Comments
 (0)