Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-387) Validate before remove rollback folder
  (GH-349) Ignore PowerShell InitializeDefaultDrives
  • Loading branch information
ferventcoder committed Sep 18, 2015
2 parents f76d9cd + bb270cb commit 675bf1d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,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");

Expand Down
9 changes: 6 additions & 3 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public ConcurrentDictionary<string, PackageResult> 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
Expand All @@ -401,10 +401,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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class PowershellService : IPowershellService
private readonly IFileSystem _fileSystem;
private readonly string _customImports;
private const string OPERATION_COMPLETED_SUCCESSFULLY = "The operation completed successfully.";
private const string INITIALIZE_DEFAULT_DRIVES = "Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed.";

public PowershellService(IFileSystem fileSystem)
: this(fileSystem, new CustomString(string.Empty))
Expand Down Expand Up @@ -275,7 +276,7 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
(s, e) =>
{
if (string.IsNullOrWhiteSpace(e.Data)) return;
if (e.Data.is_equal_to(OPERATION_COMPLETED_SUCCESSFULLY))
if (e.Data.is_equal_to(OPERATION_COMPLETED_SUCCESSFULLY) || e.Data.is_equal_to(INITIALIZE_DEFAULT_DRIVES))
{
this.Log().Info(() => " " + e.Data);
}
Expand Down

0 comments on commit 675bf1d

Please sign in to comment.