Fix issue when creating assets.json and folder does not exist. Improve module/theme uninstall to remove empty folders.

This commit is contained in:
Shaun Walker 2021-02-26 09:08:25 -05:00
parent ba54076c61
commit 12fd845ed5
3 changed files with 14 additions and 0 deletions

View File

@ -135,6 +135,7 @@ namespace Oqtane.Controllers
{ {
// use assets.json to clean up file resources // use assets.json to clean up file resources
List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json"))); List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json")));
assets.Reverse();
foreach(string asset in assets) foreach(string asset in assets)
{ {
// legacy support for assets that were stored as absolute paths // legacy support for assets that were stored as absolute paths
@ -142,6 +143,10 @@ namespace Oqtane.Controllers
if (System.IO.File.Exists(filepath)) if (System.IO.File.Exists(filepath))
{ {
System.IO.File.Delete(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); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assets Removed For {ModuleDefinitionName}", moduledefinition.ModuleDefinitionName);

View File

@ -63,6 +63,7 @@ namespace Oqtane.Controllers
{ {
// use assets.json to clean up file resources // use assets.json to clean up file resources
List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json"))); List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(Path.Combine(assetpath, "assets.json")));
assets.Reverse();
foreach (string asset in assets) foreach (string asset in assets)
{ {
// legacy support for assets that were stored as absolute paths // legacy support for assets that were stored as absolute paths
@ -70,6 +71,10 @@ namespace Oqtane.Controllers
if (System.IO.File.Exists(filepath)) if (System.IO.File.Exists(filepath))
{ {
System.IO.File.Delete(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); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}", theme.ThemeName);

View File

@ -126,6 +126,10 @@ namespace Oqtane.Infrastructure
{ {
File.Delete(manifestpath); File.Delete(manifestpath);
} }
if (!Directory.Exists(Path.GetDirectoryName(manifestpath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(manifestpath));
}
File.WriteAllText(manifestpath, JsonSerializer.Serialize(assets)); File.WriteAllText(manifestpath, JsonSerializer.Serialize(assets));
} }
} }