fix(bundler/nsis): remove empty resources folders on uninstall (#8263)

* fix(bundler/nsis): remove empty resources folders on uninstall

* make clippy happy for once
This commit is contained in:
Fabian-Lars 2023-11-20 13:43:47 +01:00 committed by GitHub
parent 8accd6940e
commit f26d9f0884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -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.

View File

@ -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));

View File

@ -533,7 +533,6 @@ Section Install
; Copy resources
{{#each resources_dirs}}
; `\\` is not a typo.
CreateDirectory "$INSTDIR\\{{this}}"
{{/each}}
{{#each resources}}
@ -623,7 +622,6 @@ Section Uninstall
; Delete resources
{{#each resources}}
Delete "$INSTDIR\\{{this.[1]}}"
RMDir "$INSTDIR\\{{this.[0]}}"
{{/each}}
; Delete external binaries
@ -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