Skip to content

Commit

Permalink
(GH-1238) Save extra info about installed packages
Browse files Browse the repository at this point in the history
Allow saving more information about a package when it is available.
  • Loading branch information
ferventcoder committed May 1, 2017
1 parent b03b760 commit 73b7035
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public ChocolateyPackageInformation(IPackage package)
public bool HasSilentUninstall { get; set; }
public bool IsSideBySide { get; set; }
public bool IsPinned { get; set; }
public string ExtraInformation { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class ChocolateyPackageInformationService : IChocolateyPackageInformati
private const string SIDE_BY_SIDE_FILE = ".sxs";
private const string PIN_FILE = ".pin";
private const string ARGS_FILE = ".arguments";
private const string EXTRA_FILE = ".extra";
private const string VERSION_OVERRIDE_FILE = ".version";

public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService)
Expand Down Expand Up @@ -84,6 +85,8 @@ public ChocolateyPackageInformation get_package_information(IPackage package)
packageInformation.IsPinned = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, PIN_FILE));
var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE);
if (_fileSystem.file_exists(argsFile)) packageInformation.Arguments = _fileSystem.read_file(argsFile);
var extraInfoFile = _fileSystem.combine_paths(pkgStorePath, EXTRA_FILE);
if (_fileSystem.file_exists(extraInfoFile)) packageInformation.ExtraInformation = _fileSystem.read_file(extraInfoFile);

var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE);
if (_fileSystem.file_exists(versionOverrideFile))
Expand Down Expand Up @@ -136,7 +139,18 @@ public void save_package_information(ChocolateyPackageInformation packageInforma
else
{
_fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, ARGS_FILE));
}
}

if (!string.IsNullOrWhiteSpace(packageInformation.ExtraInformation))
{
var extraFile = _fileSystem.combine_paths(pkgStorePath, EXTRA_FILE);
if (_fileSystem.file_exists(extraFile)) _fileSystem.delete_file(extraFile);
_fileSystem.write_file(extraFile, packageInformation.ExtraInformation);
}
else
{
_fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, EXTRA_FILE));
}

if (packageInformation.VersionOverride != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
if (key != null) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, key.InstallLocation, EnvironmentVariableTarget.Process);
}

_packageInfoService.save_package_information(pkgInfo);
update_package_information(pkgInfo);
ensure_bad_package_path_is_clean(config, packageResult);
EventManager.publish(new HandlePackageResultCompletedMessage(packageResult, config, commandName));

Expand Down Expand Up @@ -455,6 +455,11 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
}
}

protected virtual void update_package_information(ChocolateyPackageInformation pkgInfo)
{
_packageInfoService.save_package_information(pkgInfo);
}

private string capture_arguments(ChocolateyConfiguration config, PackageResult packageResult)
{
var arguments = new StringBuilder();
Expand Down

0 comments on commit 73b7035

Please sign in to comment.