From c8f757991035f136184fc7299e45bf18ec4bc0b0 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sat, 21 Feb 2015 10:03:12 -0600 Subject: [PATCH] (GH-10) Backup configuration files Backup configuration files as a native way to keep around the configuration file so that it can be compared to the new one that overwrite the old (based on the merge strategy from nuget). This is naive yes, more of GH-10 will later handle this better. --- .../infrastructure.app/ApplicationParameters.cs | 2 ++ .../infrastructure.app/services/NugetService.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 693228675a..082aa2de9f 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -61,6 +61,8 @@ public static class ApplicationParameters /// public static int DefaultWaitForExitInSeconds = 2700; + public static readonly string[] ConfigFileExtensions = new string[] {".autoconf",".config",".conf",".cfg",".jsc",".json",".jsonp",".ini",".xml",".yaml"}; + public static class Tools { //public static readonly string WebPiCmdExe = _fileSystem.combine_paths(InstallLocation, "nuget.exe"); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 2f46bbc927..4a2a2a9a06 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -612,6 +612,22 @@ public void backup_existing_version(ChocolateyConfiguration config, IPackage ins this.Log().Error("Error during backup (reset phase):{0} {1}".format_with(Environment.NewLine, ex.Message)); } } + + backup_configuration_files(pkgInstallPath, installedPackage.Version.to_string()); + + } + } + + private void backup_configuration_files(string packageInstallPath, string version) + { + var configFiles = _fileSystem.get_files(packageInstallPath, ApplicationParameters.ConfigFileExtensions, SearchOption.AllDirectories); + foreach (var file in configFiles.or_empty_list_if_null()) + { + var backupName = "{0}.{1}.{2}".format_with(_fileSystem.get_file_name_without_extension(file), version, _fileSystem.get_file_extension(file)); + + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.copy_file(file, _fileSystem.combine_paths(_fileSystem.get_directory_name(file), backupName), overwriteExisting: true), + "Error backing up configuration file"); } }