Skip to content

Commit

Permalink
fix(bundler/nsis): remove empty resources folders on uninstall (#8263)
Browse files Browse the repository at this point in the history
* fix(bundler/nsis): remove empty resources folders on uninstall

* make clippy happy for once
  • Loading branch information
FabianLars authored Nov 20, 2023
1 parent 8accd69 commit f26d9f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changes/nsis-leftover-dirs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tauri-apps/cli": patch:bug
"tauri-cli": patch:bug
"tauri-bundler": patch:bug
---

Fixes an issue in the NSIS installer which caused the uninstallation to leave empty folders on the system if the `resources` feature was used.
11 changes: 11 additions & 0 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ fn build_nsis_app_installer(
let resources = generate_resource_data(settings)?;
let resources_dirs =
std::collections::HashSet::<PathBuf>::from_iter(resources.values().map(|r| r.0.to_owned()));

let mut resources_ancestors = resources_dirs
.iter()
.flat_map(|p| p.ancestors())
.collect::<Vec<_>>();
resources_ancestors.sort_unstable();
resources_ancestors.dedup();
resources_ancestors.sort_by_key(|p| std::cmp::Reverse(p.components().count()));
resources_ancestors.pop(); // Last one is always ""

data.insert("resources_ancestors", to_json(resources_ancestors));
data.insert("resources_dirs", to_json(resources_dirs));
data.insert("resources", to_json(&resources));

Expand Down
11 changes: 8 additions & 3 deletions tooling/bundler/src/bundle/windows/templates/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ Section Install

; Copy resources
{{#each resources_dirs}}
; `\\` is not a typo.
CreateDirectory "$INSTDIR\\{{this}}"
{{/each}}
{{#each resources}}
Expand Down Expand Up @@ -623,7 +622,6 @@ Section Uninstall
; Delete resources
{{#each resources}}
Delete "$INSTDIR\\{{this.[1]}}"
RMDir "$INSTDIR\\{{this.[0]}}"
{{/each}}

; Delete external binaries
Expand All @@ -634,7 +632,14 @@ Section Uninstall
; Delete uninstaller
Delete "$INSTDIR\uninstall.exe"

RMDir "$INSTDIR"
${If} $DeleteAppDataCheckboxState == 1
RMDir /R /REBOOTOK "$INSTDIR"
${Else}
{{#each resources_ancestors}}
RMDir /REBOOTOK "$INSTDIR\\{{this}}"
{{/each}}
RMDir "$INSTDIR"
${EndIf}

; Remove start menu shortcut
!insertmacro MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder
Expand Down

0 comments on commit f26d9f0

Please sign in to comment.