Skip to content

Commit

Permalink
(GH-198) Set and remove a pending file
Browse files Browse the repository at this point in the history
Once a package install/upgrade is passed from NuGet Core to Chocolatey,
we are in a pending state where the package files exist but more work
is to be done. Create a pending file for the package that tells
Chocolatey that the package is not yet finished installing in case it
gets interrupted for some reason. Also ensure that the pending file is
cleaned up if the package installation is successful.
  • Loading branch information
ferventcoder committed May 28, 2016
1 parent a3a9d83 commit 5f36303
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 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 @@ -87,6 +87,8 @@ public static class Environment
public static readonly string HashProviderFileTooBig = "UnableToDetectChanges_FileTooBig";
public static readonly string HashProviderFileLocked = "UnableToDetectChanges_FileLocked";

public static readonly string PackagePendingFileName = ".chocolateyPending";

public static class Tools
{
//public static readonly string WebPiCmdExe = _fileSystem.combine_paths(InstallLocation, "nuget.exe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public void randomly_notify_about_pro_business(ChocolateyConfiguration config, s

public void handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName)
{
set_pending(packageResult, config);
var pkgInfo = _packageInfoService.get_package_information(packageResult.Package);
if (config.AllowMultipleVersions)
{
Expand Down Expand Up @@ -315,10 +316,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
_configTransformService.run(packageResult, config);
pkgInfo.FilesSnapshot = _filesService.capture_package_files(packageResult, config);

if (packageResult.Success)
{
_shimgenService.install(config, packageResult);
}
if (packageResult.Success) _shimgenService.install(config, packageResult);
}
else
{
Expand All @@ -345,6 +343,8 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu

remove_rollback_if_exists(packageResult);

if (packageResult.Success) remove_pending(packageResult, config);

this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".format_with(commandName.to_string(), packageResult.Name));
}

Expand Down Expand Up @@ -1054,6 +1054,44 @@ private void remove_rollback_if_exists(PackageResult packageResult)
_nugetService.remove_rollback_directory_if_exists(packageResult.Name);
}

public void set_pending(PackageResult packageResult, ChocolateyConfiguration config)
{
var packageDirectory = packageResult.InstallLocation;
if (packageDirectory.is_equal_to(ApplicationParameters.InstallLocation) || packageDirectory.is_equal_to(ApplicationParameters.PackagesLocation))
{
packageResult.Messages.Add(
new ResultMessage(
ResultType.Error,
"Install location is not specific enough, cannot run set package to pending:{0} Erroneous install location captured as '{1}'".format_with(Environment.NewLine, packageResult.InstallLocation)
)
);

return;
}

var pendingFile = _fileSystem.combine_paths(packageDirectory, ApplicationParameters.PackagePendingFileName);
_fileSystem.write_file(pendingFile, "{0}".format_with(packageResult.Name));
}

public void remove_pending(PackageResult packageResult, ChocolateyConfiguration config)
{
var packageDirectory = packageResult.InstallLocation;
if (packageDirectory.is_equal_to(ApplicationParameters.InstallLocation) || packageDirectory.is_equal_to(ApplicationParameters.PackagesLocation))
{
packageResult.Messages.Add(
new ResultMessage(
ResultType.Error,
"Install location is not specific enough, cannot run set package to pending:{0} Erroneous install location captured as '{1}'".format_with(Environment.NewLine, packageResult.InstallLocation)
)
);

return;
}

var pendingFile = _fileSystem.combine_paths(packageDirectory, ApplicationParameters.PackagePendingFileName);
if (_fileSystem.file_exists(pendingFile)) _fileSystem.delete_file(pendingFile);
}

private IEnumerable<GenericRegistryValue> get_environment_before(ChocolateyConfiguration config, bool allowLogging = true)
{
if (config.Information.PlatformType != PlatformType.Windows) return Enumerable.Empty<GenericRegistryValue>();
Expand Down

0 comments on commit 5f36303

Please sign in to comment.