From 519fcc2e26baa88d3226f677f02cef2845d5b2d1 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Thu, 13 May 2021 09:32:26 +0100 Subject: [PATCH] (#357) Ensure to use full file path When creating an output export file from a path like "packages.config" we need to ensure to use the full file path to the file, otherwise it won't be able to backup the file correctly, if it already exists on the file system. Without this, we were seeing errors when trying to ensure that the directory that the file was contained in was created, since this was an empty string. --- .../commands/ChocolateyExportCommand.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs index a7f568d4d1..1f46a2ce1f 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs @@ -166,13 +166,14 @@ public void run(ChocolateyConfiguration configuration) xw.Flush(); } - var fileExists = _fileSystem.file_exists(configuration.ExportCommand.OutputFilePath); + var fullOutputFilePath = _fileSystem.get_full_path(configuration.ExportCommand.OutputFilePath); + var fileExists = _fileSystem.file_exists(fullOutputFilePath); // If the file doesn't already exist, just write the new one out directly if (!fileExists) { _fileSystem.write_file( - configuration.ExportCommand.OutputFilePath, + fullOutputFilePath, stringWriter.GetStringBuilder().ToString(), new UTF8Encoding(false)); @@ -181,12 +182,12 @@ public void run(ChocolateyConfiguration configuration) // Otherwise, create an update file, and resiliently move it into place. - var tempUpdateFile = configuration.ExportCommand.OutputFilePath + "." + Process.GetCurrentProcess().Id + ".update"; + var tempUpdateFile = fullOutputFilePath + "." + Process.GetCurrentProcess().Id + ".update"; _fileSystem.write_file(tempUpdateFile, stringWriter.GetStringBuilder().ToString(), new UTF8Encoding(false)); - _fileSystem.replace_file(tempUpdateFile, configuration.ExportCommand.OutputFilePath, configuration.ExportCommand.OutputFilePath + ".backup"); + _fileSystem.replace_file(tempUpdateFile, fullOutputFilePath, fullOutputFilePath + ".backup"); } }, errorMessage: "Error exporting currently installed packages",