Skip to content

Commit

Permalink
VCI-157: Backup appsettings.json on update (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored Sep 23, 2021
1 parent 81c5966 commit 6a6f6ca
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions PlatformTools/Build.PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nuke.Common;
using Nuke.Common.IO;
Expand Down Expand Up @@ -153,7 +154,26 @@ private async Task InstallPlatformAsync(string platformVersion)
}

await HttpTasks.HttpDownloadFileAsync(platformAssetUrl, platformZip);

// backup appsettings.json if exists
var tempFile = string.Empty;
if (File.Exists(AppsettingsPath))
{
tempFile = Path.GetTempFileName();
FileSystemTasks.MoveFile(AppsettingsPath, tempFile, FileExistsPolicy.Overwrite);
}

CompressionTasks.Uncompress(platformZip, RootDirectory);

// return appsettings.json back
if (!string.IsNullOrEmpty(tempFile))
{
var bakFileName = new StringBuilder("appsettings.")
.Append(DateTime.Now.ToString("MMddyyHHmmss"))
.Append(".bak");
var destinationSettingsPath = !Force ? AppsettingsPath : Path.Join(Path.GetDirectoryName(AppsettingsPath), bakFileName.ToString());
FileSystemTasks.MoveFile(tempFile, destinationSettingsPath, FileExistsPolicy.Overwrite);
}
}
}

Expand Down Expand Up @@ -184,6 +204,7 @@ private bool NeedToInstallPlatform(string version)

public Target InstallModules => _ => _
.After(InstallPlatform)
.OnlyWhenDynamic(() => !PlatformParameter)
.Executes(() =>
{
var packageManifest = PackageManager.FromFile(PackageManifestPath);
Expand Down

0 comments on commit 6a6f6ca

Please sign in to comment.