From 12fd845ed593d920e82b940de2f51ba7383382db Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Fri, 26 Feb 2021 09:08:25 -0500 Subject: [PATCH] Fix issue when creating assets.json and folder does not exist. Improve module/theme uninstall to remove empty folders. --- Oqtane.Server/Controllers/ModuleDefinitionController.cs | 5 +++++ Oqtane.Server/Controllers/ThemeController.cs | 5 +++++ Oqtane.Server/Infrastructure/InstallationManager.cs | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/Oqtane.Server/Controllers/ModuleDefinitionController.cs b/Oqtane.Server/Controllers/ModuleDefinitionController.cs index dc371214..f417ce33 100644 --- a/Oqtane.Server/Controllers/ModuleDefinitionController.cs +++ b/Oqtane.Server/Controllers/ModuleDefinitionController.cs @@ -135,6 +135,7 @@ namespace Oqtane.Controllers { // use assets.json to clean up file resources List assets = JsonSerializer.Deserialize>(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json"))); + assets.Reverse(); foreach(string asset in assets) { // legacy support for assets that were stored as absolute paths @@ -142,6 +143,10 @@ namespace Oqtane.Controllers if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); + if (!Directory.EnumerateFiles(Path.GetDirectoryName(filepath)).Any()) + { + Directory.Delete(Path.GetDirectoryName(filepath)); + } } } _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assets Removed For {ModuleDefinitionName}", moduledefinition.ModuleDefinitionName); diff --git a/Oqtane.Server/Controllers/ThemeController.cs b/Oqtane.Server/Controllers/ThemeController.cs index 615080e9..851aeb68 100644 --- a/Oqtane.Server/Controllers/ThemeController.cs +++ b/Oqtane.Server/Controllers/ThemeController.cs @@ -63,6 +63,7 @@ namespace Oqtane.Controllers { // use assets.json to clean up file resources List assets = JsonSerializer.Deserialize>(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json"))); + assets.Reverse(); foreach (string asset in assets) { // legacy support for assets that were stored as absolute paths @@ -70,6 +71,10 @@ namespace Oqtane.Controllers if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); + if (!Directory.EnumerateFiles(Path.GetDirectoryName(filepath)).Any()) + { + Directory.Delete(Path.GetDirectoryName(filepath)); + } } } _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}", theme.ThemeName); diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index f14e8ae1..3b627c70 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -126,6 +126,10 @@ namespace Oqtane.Infrastructure { File.Delete(manifestpath); } + if (!Directory.Exists(Path.GetDirectoryName(manifestpath))) + { + Directory.CreateDirectory(Path.GetDirectoryName(manifestpath)); + } File.WriteAllText(manifestpath, JsonSerializer.Serialize(assets)); } }