Merge pull request #515 from sbwalker/master

fixes to upgrade project
This commit is contained in:
Shaun Walker 2020-05-20 11:56:32 -04:00 committed by GitHub
commit 1355233b92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 35 deletions

View File

@ -26,7 +26,7 @@
<Label HelpText="Upload a framework package and select Install to complete the installation">Framework: </Label> <Label HelpText="Upload a framework package and select Install to complete the installation">Framework: </Label>
</td> </td>
<td> <td>
<FileManager Filter="nupkg" ShowFiles="false" Folder="Framework" /> <FileManager Filter="nupkg" Folder="Framework" />
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -18,10 +18,11 @@
</metadata> </metadata>
<files> <files>
<file src="..\Oqtane.Client\bin\Release\netstandard2.1\Oqtane.Client.dll" target="lib" /> <file src="..\Oqtane.Client\bin\Release\netstandard2.1\Oqtane.Client.dll" target="lib" />
<file src="..\Oqtane.Client\bin\Release\netstandard2.1\Oqtane.Client.pdb" target="lib" />
<file src="..\Oqtane.Server\bin\Release\netcoreapp3.1\Oqtane.Server.dll" target="lib" /> <file src="..\Oqtane.Server\bin\Release\netcoreapp3.1\Oqtane.Server.dll" target="lib" />
<file src="..\Oqtane.Server\bin\Release\netcoreapp3.1\Oqtane.Server.pdb" target="lib" />
<file src="..\Oqtane.Shared\bin\Release\netstandard2.1\Oqtane.Shared.dll" target="lib" /> <file src="..\Oqtane.Shared\bin\Release\netstandard2.1\Oqtane.Shared.dll" target="lib" />
<file src="..\Oqtane.Server\bin\Release\netcoreapp3.1\Oqtane.Upgrade.dll" target="lib" /> <file src="..\Oqtane.Shared\bin\Release\netstandard2.1\Oqtane.Shared.pdb" target="lib" />
<file src="..\Oqtane.Server\bin\Release\netcoreapp3.1\Oqtane.Upgrade.dll" target="lib" />
<file src="..\Oqtane.Server\wwwroot\**\*.*" target="wwwroot" /> <file src="..\Oqtane.Server\wwwroot\**\*.*" target="wwwroot" />
</files> </files>
</package> </package>

View File

@ -80,14 +80,10 @@ namespace Oqtane.Infrastructure
// if compatible with framework version // if compatible with framework version
if (frameworkversion == "" || Version.Parse(Constants.Version).CompareTo(Version.Parse(frameworkversion)) >= 0) if (frameworkversion == "" || Version.Parse(Constants.Version).CompareTo(Version.Parse(frameworkversion)) >= 0)
{ {
string name = ""; // module and theme packages must be in form of name.1.0.0.nupkg
if (folder != "Framework") string name = Path.GetFileNameWithoutExtension(packagename);
{ string[] segments = name?.Split('.');
// module and theme packages must be in form of name.1.0.0.nupkg if (segments != null) name = string.Join('.', segments, 0, segments.Length - 3);
name = Path.GetFileNameWithoutExtension(packagename);
string[] segments = name?.Split('.');
if (segments != null) name = string.Join('.', segments, 0, segments.Length - 3);
}
// deploy to appropriate locations // deploy to appropriate locations
foreach (ZipArchiveEntry entry in archive.Entries) foreach (ZipArchiveEntry entry in archive.Entries)

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Reflection; using System.Reflection;
@ -10,6 +11,11 @@ namespace Oqtane.Upgrade
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
// for testing purposes set Oqtane.Upgrade as startup project and modify values below
//Array.Resize(ref args, 2);
//args[0] = @"C:\yourpath\oqtane.framework\Oqtane.Server";
//args[1] = @"C:\yourpath\oqtane.framework\Oqtane.Server\wwwroot";
// requires 2 arguments - the contentrootpath and the webrootpath of the site // requires 2 arguments - the contentrootpath and the webrootpath of the site
if (args.Length == 2) if (args.Length == 2)
{ {
@ -32,7 +38,7 @@ namespace Oqtane.Upgrade
// take the app offline // take the app offline
if (File.Exists(Path.Combine(webrootfolder, "app_offline.bak"))) if (File.Exists(Path.Combine(webrootfolder, "app_offline.bak")))
{ {
File.Move(Path.Combine(webrootfolder, "app_offline.bak"), Path.Combine(contentrootfolder, "app_offline.htm")); File.Copy(Path.Combine(webrootfolder, "app_offline.bak"), Path.Combine(contentrootfolder, "app_offline.htm"), true);
} }
// get list of files in package // get list of files in package
@ -41,26 +47,29 @@ namespace Oqtane.Upgrade
{ {
foreach (ZipArchiveEntry entry in archive.Entries) foreach (ZipArchiveEntry entry in archive.Entries)
{ {
if (Path.GetExtension(entry.FullName) == ".dll") switch (Path.GetDirectoryName(entry.FullName).Split('\\')[0])
{ {
files.Add(Path.GetFileName(entry.FullName)); case "lib":
files.Add(Path.Combine(binfolder, Path.GetFileName(entry.FullName)));
break;
case "wwwroot":
files.Add(Path.Combine(webrootfolder, entry.FullName.Replace("wwwroot/", "").Replace("/","\\")));
break;
} }
} }
} }
// ensure files are not locked // ensure files are not locked
string filename; if (CanAccessFiles(files))
if (CanAccessFiles(files, binfolder))
{ {
// create backup // create backup
foreach (string file in files) foreach (string file in files)
{ {
filename = Path.Combine(binfolder, Path.GetFileName(file)); if (File.Exists(file + ".bak"))
if (File.Exists(filename.Replace(".dll", ".bak")))
{ {
File.Delete(filename.Replace(".dll", ".bak")); File.Delete(file + ".bak");
} }
File.Move(filename, filename.Replace(".dll", ".bak")); File.Move(file, file + ".bak");
} }
// extract files // extract files
@ -71,10 +80,19 @@ namespace Oqtane.Upgrade
{ {
foreach (ZipArchiveEntry entry in archive.Entries) foreach (ZipArchiveEntry entry in archive.Entries)
{ {
filename = Path.GetFileName(entry.FullName); string filename = "";
switch (Path.GetDirectoryName(entry.FullName).Split('\\')[0])
{
case "lib":
filename = Path.Combine(binfolder, Path.GetFileName(entry.FullName));
break;
case "wwwroot":
filename = Path.Combine(webrootfolder, entry.FullName.Replace("wwwroot/", "").Replace("/", "\\"));
break;
}
if (files.Contains(filename)) if (files.Contains(filename))
{ {
entry.ExtractToFile(Path.Combine(binfolder, filename), true); entry.ExtractToFile(filename, true);
} }
} }
} }
@ -91,29 +109,27 @@ namespace Oqtane.Upgrade
// clean up backup // clean up backup
foreach (string file in files) foreach (string file in files)
{ {
filename = Path.Combine(binfolder, Path.GetFileName(file)); if (File.Exists(file + ".bak"))
if (File.Exists(filename.Replace(".dll", ".bak")))
{ {
File.Delete(filename.Replace(".dll", ".bak")); File.Delete(file + ".bak");
} }
} }
// delete package
File.Delete(packagename);
} }
else else
{ {
// restore on failure // restore on failure
foreach (string file in files) foreach (string file in files)
{ {
filename = Path.Combine(binfolder, Path.GetFileName(file)); if (File.Exists(file))
if (File.Exists(filename))
{ {
File.Delete(filename); File.Delete(file);
} }
File.Move(filename.Replace(".dll", ".bak"), filename); File.Move(file + ".bak", file);
} }
} }
// delete package
File.Delete(packagename);
} }
// bring the app back online // bring the app back online
@ -126,7 +142,7 @@ namespace Oqtane.Upgrade
} }
} }
private static bool CanAccessFiles(List<string> files, string folder) private static bool CanAccessFiles(List<string> files)
{ {
// ensure files are not locked by another process - the shutdownTimeLimit defines the duration for app shutdown // ensure files are not locked by another process - the shutdownTimeLimit defines the duration for app shutdown
bool canAccess = true; bool canAccess = true;
@ -134,7 +150,7 @@ namespace Oqtane.Upgrade
int i = 0; int i = 0;
while (i < (files.Count - 1) && canAccess) while (i < (files.Count - 1) && canAccess)
{ {
string filepath = Path.Combine(folder, Path.GetFileName(files[i])); string filepath = files[i];
int attempts = 0; int attempts = 0;
bool locked = true; bool locked = true;
// try up to 30 times // try up to 30 times