Fix bug: not cleaning up temp dirs

This commit is contained in:
Caelan Sayler
2025-05-26 21:44:14 +01:00
parent a2640a354e
commit a29e21c874
4 changed files with 18 additions and 10 deletions

View File

@@ -22,12 +22,16 @@ pub fn uninstall(locator: &VelopackLocator, delete_self: bool) -> Result<()> {
info!("Removing directory '{:?}'", root_path); info!("Removing directory '{:?}'", root_path);
let _ = remove_dir_all::remove_dir_contents(&root_path); let _ = remove_dir_all::remove_dir_contents(&root_path);
let temp_dir = std::env::temp_dir();
let temp_dir = temp_dir.join(format!("velopack_{}", locator.get_manifest_id()));
info!("Removing directory '{:?}'", temp_dir);
let _ = remove_dir_all::remove_dir_all(&temp_dir);
if let Err(e) = windows::registry::remove_uninstall_entry(&locator) { if let Err(e) = windows::registry::remove_uninstall_entry(&locator) {
error!("Unable to remove uninstall registry entry ({}).", e); error!("Unable to remove uninstall registry entry ({}).", e);
} }
// if it returns true, it was a success.
// if it returns false, it was completed with errors which the user should be notified of.
let app_title = locator.get_manifest_title(); let app_title = locator.get_manifest_title();
info!("Finished successfully."); info!("Finished successfully.");

View File

@@ -85,7 +85,7 @@ public static class MsiBuilder
var wixArch = data.IsArm64 ? "arm64" : data.Is64Bit ? "x64" : "x86"; var wixArch = data.IsArm64 ? "arm64" : data.Is64Bit ? "x64" : "x86";
Log.Info($"Configuring WiX in {wixArch} mode"); Log.Info($"Configuring WiX in {wixArch} mode");
var _1 = TempUtil.GetTempDirectory(out var outputDir); using var _1 = TempUtil.GetTempDirectory(out var outputDir);
var wixId = data.WixId; var wixId = data.WixId;
var wxsPath = Path.Combine(outputDir, wixId + ".wxs"); var wxsPath = Path.Combine(outputDir, wixId + ".wxs");
var localizationPath = Path.Combine(outputDir, wixId + "_en-US.wxs"); var localizationPath = Path.Combine(outputDir, wixId + "_en-US.wxs");

View File

@@ -97,14 +97,14 @@
<!-- deferred actions do not have access to msi properties and read all data from "CustomActionData" which is a string, <!-- deferred actions do not have access to msi properties and read all data from "CustomActionData" which is a string,
so we delimit with &quot; which is unlikely (or disallowed) from to appearing in filenames / paths.--> so we delimit with &quot; which is unlikely (or disallowed) from to appearing in filenames / paths.-->
<CustomAction Id="SetRustCleanupData" Property="RustCleanup" Value="[INSTALLFOLDER]&quot;[RustAppId]" Execute="immediate" <CustomAction Id="SetRustCleanupData" Property="RustCleanup" Value="[INSTALLFOLDER]&quot;[RustAppId]&quot;[TempFolder]" Execute="immediate"
Return="check"/> Return="check"/>
<CustomAction Id="RustCleanup" BinaryRef="RustDll" DllEntry="CleanupDeferred" Execute="deferred" Impersonate="no" Return="ignore"/> <CustomAction Id="RustCleanup" BinaryRef="RustDll" DllEntry="CleanupDeferred" Execute="deferred" Impersonate="no" Return="ignore"/>
<CustomAction Id="RustLaunchApplication" BinaryRef="RustDll" DllEntry="LaunchApplication" Impersonate="yes" Execute="immediate" <CustomAction Id="RustLaunchApplication" BinaryRef="RustDll" DllEntry="LaunchApplication" Impersonate="yes" Execute="immediate"
Return="ignore"/> Return="ignore"/>
<InstallUISequence> <InstallUISequence>
<Custom Action="RustEarlyBootstrap" Before="AppSearch" Condition="REMOVE=&quot;&quot;"/> <Custom Action="RustEarlyBootstrap" Before="AppSearch" Condition="NOT REMOVE AND NOT RustRuntimeDependencies"/>
</InstallUISequence> </InstallUISequence>
<InstallExecuteSequence> <InstallExecuteSequence>

View File

@@ -48,19 +48,23 @@ pub extern "system" fn CleanupDeferred(h_install: MSIHANDLE) -> c_uint {
let mut custom_data = custom_data.split('"'); let mut custom_data = custom_data.split('"');
let install_dir = custom_data.next(); let install_dir = custom_data.next();
let app_id = custom_data.next(); let app_id = custom_data.next();
let temp_dir = custom_data.next();
show_debug_message("CleanupDeferred", format!("install_dir={:?}, app_id={:?}", install_dir, app_id)); show_debug_message("CleanupDeferred", format!("install_dir={:?}, app_id={:?}, temp_dir={:?}", install_dir, app_id, temp_dir));
if let Some(install_dir) = install_dir { if let Some(install_dir) = install_dir {
if let Err(e) = remove_dir_all::remove_dir_all(install_dir) { if let Err(e) = remove_dir_all::remove_dir_all(install_dir) {
show_debug_message("CleanupDeferred", format!("Failed to remove install directory: {}", e)); show_debug_message("CleanupDeferred", format!("Failed to remove install directory: {:?} {}", install_dir, e));
} }
} }
if let Some(app_id) = app_id { if let Some(app_id) = app_id {
let temp_dir = std::env::temp_dir(); if let Some(temp_dir) = temp_dir {
if let Err(e) = remove_dir_all::remove_dir_all(temp_dir.join(format!("velopack_{}", app_id))) { let temp_dir = PathBuf::from(temp_dir);
show_debug_message("CleanupDeferred", format!("Failed to remove temp directory: {}", e)); let temp_dir = temp_dir.join(format!("velopack_{}", app_id));
if let Err(e) = remove_dir_all::remove_dir_all(&temp_dir) {
show_debug_message("CleanupDeferred", format!("Failed to remove temp directory: {:?} {}", temp_dir, e));
}
} }
} }