add defensive logic to package installer

This commit is contained in:
Shaun Walker 2023-03-29 08:47:54 -04:00
parent 3a79fa074a
commit 82221f54c5
2 changed files with 86 additions and 81 deletions

View File

@ -190,7 +190,7 @@ else
try try
{ {
await PackageService.InstallPackagesAsync(); await PackageService.InstallPackagesAsync();
AddModuleMessage(string.Format(Localizer["Success.Translation.Install"], NavigateUrl("admin/system")), MessageType.Success); AddModuleMessage(string.Format(Localizer["Success.Language.Install"], NavigateUrl("admin/system")), MessageType.Success);
_install = false; _install = false;
StateHasChanged(); StateHasChanged();
} }

View File

@ -30,15 +30,12 @@ namespace Oqtane.Infrastructure
public void InstallPackages() public void InstallPackages()
{ {
if (!InstallPackages(_environment.WebRootPath, _environment.ContentRootPath)) InstallPackages(_environment.WebRootPath, _environment.ContentRootPath);
{
// error installing packages
}
} }
public static bool InstallPackages(string webRootPath, string contentRootPath) public static bool InstallPackages(string webRootPath, string contentRootPath)
{ {
bool install = false; bool install = true;
string binPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); string binPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
string sourceFolder = Path.Combine(contentRootPath, "Packages"); string sourceFolder = Path.Combine(contentRootPath, "Packages");
@ -81,6 +78,8 @@ namespace Oqtane.Infrastructure
// iterate through Nuget packages in source folder // iterate through Nuget packages in source folder
foreach (string packagename in Directory.GetFiles(sourceFolder, "*.nupkg")) foreach (string packagename in Directory.GetFiles(sourceFolder, "*.nupkg"))
{
try
{ {
// iterate through files // iterate through files
using (ZipArchive archive = ZipFile.OpenRead(packagename)) using (ZipArchive archive = ZipFile.OpenRead(packagename))
@ -170,10 +169,16 @@ namespace Oqtane.Infrastructure
} }
} }
} }
}
catch (Exception ex)
{
// problem installing package - logging is not possible as this is a static method
Debug.WriteLine($"Oqtane Error: Installing Package {packagename} - {ex}");
install = false;
}
// remove package // remove package
File.Delete(packagename); File.Delete(packagename);
install = true;
} }
return install; return install;