Skip to content

Commit

Permalink
(GH-10) Backup configuration files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Feb 21, 2015
1 parent 5d822ba commit c8f7579
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static class ApplicationParameters
/// </summary>
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");
Expand Down
16 changes: 16 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down

1 comment on commit c8f7579

@ferventcoder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been GH-110.

Please sign in to comment.