Merge pull request #2299 from chlupac/InstallManFix

Fix - InstallationManager crash when package folders are missing
This commit is contained in:
Shaun Walker 2022-07-19 13:12:43 -04:00 committed by GitHub
commit ded6c9c199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,26 +48,35 @@ namespace Oqtane.Infrastructure
}
// move packages to secure /Packages folder
foreach (var folder in "Modules,Themes,Packages".Split(","))
foreach (var folderName in "Modules,Themes,Packages".Split(","))
{
foreach(var file in Directory.GetFiles(Path.Combine(webRootPath, folder), "*.nupkg*"))
string folder = Path.Combine(webRootPath, folderName);
if (Directory.Exists(folder))
{
var destinationFile = Path.Combine(sourceFolder, Path.GetFileName(file));
if (File.Exists(destinationFile))
foreach (var file in Directory.GetFiles(folder, "*.nupkg*"))
{
File.Delete(destinationFile);
}
if (destinationFile.ToLower().EndsWith(".nupkg.bak"))
{
// leave a copy in the current folder as it is distributed with the core framework
File.Copy(file, destinationFile);
}
else
{
// move to destination
File.Move(file, destinationFile);
var destinationFile = Path.Combine(sourceFolder, Path.GetFileName(file));
if (File.Exists(destinationFile))
{
File.Delete(destinationFile);
}
if (destinationFile.ToLower().EndsWith(".nupkg.bak"))
{
// leave a copy in the current folder as it is distributed with the core framework
File.Copy(file, destinationFile);
}
else
{
// move to destination
File.Move(file, destinationFile);
}
}
}
else
{
Directory.CreateDirectory(folder);
}
}
// iterate through Nuget packages in source folder
@ -200,7 +209,7 @@ namespace Oqtane.Infrastructure
string[] packages = Directory.GetFiles(Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder), PackageName + "*.log");
if (packages.Length > 0)
{
packagename = packages[packages.Length - 1]; // use highest version
packagename = packages[packages.Length - 1]; // use highest version
}
if (!string.IsNullOrEmpty(packagename))
@ -245,7 +254,7 @@ namespace Oqtane.Infrastructure
string[] packages = Directory.GetFiles(folder, Constants.PackageId + ".*.nupkg");
if (packages.Length > 0)
{
packagename = packages[packages.Length - 1]; // use highest version
packagename = packages[packages.Length - 1]; // use highest version
}
if (packagename != "")