diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index a112ac9b36..a59879659c 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -703,7 +703,10 @@ private void rollback_previous_version(ChocolateyConfiguration config, PackageRe } } + rollbackDirectory = _fileSystem.get_full_path(rollbackDirectory); + if (string.IsNullOrWhiteSpace(rollbackDirectory) || !_fileSystem.directory_exists(rollbackDirectory)) return; + if (!rollbackDirectory.StartsWith(ApplicationParameters.PackageBackupLocation) || rollbackDirectory.is_equal_to(ApplicationParameters.PackageBackupLocation)) return; this.Log().Debug("Attempting rollback"); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index de24741f83..f08f9768ff 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -376,7 +376,7 @@ public ConcurrentDictionary install_run(ChocolateyConfigu public void remove_rollback_directory_if_exists(string packageName) { - var rollbackDirectory = _fileSystem.combine_paths(ApplicationParameters.PackageBackupLocation, packageName); + var rollbackDirectory = _fileSystem.get_full_path(_fileSystem.combine_paths(ApplicationParameters.PackageBackupLocation, packageName)); if (!_fileSystem.directory_exists(rollbackDirectory)) { //search for folder @@ -385,10 +385,13 @@ public void remove_rollback_directory_if_exists(string packageName) { rollbackDirectory = possibleRollbacks.OrderByDescending(p => p).DefaultIfEmpty(string.Empty).FirstOrDefault(); } - } + rollbackDirectory = _fileSystem.get_full_path(rollbackDirectory); + } + if (string.IsNullOrWhiteSpace(rollbackDirectory) || !_fileSystem.directory_exists(rollbackDirectory)) return; - + if (!rollbackDirectory.StartsWith(ApplicationParameters.PackageBackupLocation) || rollbackDirectory.is_equal_to(ApplicationParameters.PackageBackupLocation)) return; + FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.delete_directory_if_exists(rollbackDirectory, recursive: true), "Attempted to remove '{0}' but had an error:".format_with(rollbackDirectory),