Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (maint) Skip log PowerShell resource assembly failures
  (GH-871) Fix - Uninstall zip: Path is empty string
  (maint) remove unused import
  (GH-854) Reset Exit Code between package runs
  (GH-852) Bump up the default log sizes
  (GH-867) NuGet.Core Errors Exit Code 1
  (GH-853) Handle null values better
  (GH-836) Fix - Use 32 bit 7zip
  (GH-847) Tab Completion Enhancements
  (GH-857) Fix - Sometimes paths contain null chars
  • Loading branch information
ferventcoder committed Jul 24, 2016
2 parents 252f1a3 + 16ec90a commit 8843bd7
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 26 deletions.
9 changes: 6 additions & 3 deletions src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ function script:chocoCommands($filter) {
}

function script:chocoLocalPackages($filter) {
if ($filter -ne $null -and $filter.StartsWith(".")) { return; } #file search
@(& $script:choco list $filter -lo -r --id-starts-with) | %{ $_.Split('|')[0] }
}

function script:chocoLocalPackagesUpgrade($filter) {
if ($filter -ne $null -and $filter.StartsWith(".")) { return; } #file search
@('all|') + @(& $script:choco list $filter -lo -r --id-starts-with) | where { $_ -like "$filter*" } | %{ $_.Split('|')[0] }
}

function script:chocoRemotePackages($filter) {
if ($filter -ne $null -and $filter.StartsWith(".")) { return; } #file search
@('packages.config|') + @(& $script:choco search $filter --page=0 --page-size=30 -r --id-starts-with --order-by-popularity) | where { $_ -like "$filter*" } | %{ $_.Split('|')[0] }
}

Expand All @@ -99,17 +102,17 @@ function ChocolateyTabExpansion($lastBlock) {
switch -regex ($lastBlock -replace "^$(Get-AliasPattern choco) ","") {

# Handles uninstall package names
"^uninstall\s+(?<package>[^-\s]*)$" {
"^uninstall\s+(?<package>[^\.][^-\s]*)$" {
chocoLocalPackages $matches['package']
}

# Handles install package names
"^(install)\s+(?<package>[^-\s]*)$" {
"^(install)\s+(?<package>[^\.][^-\s]+)$" {
chocoRemotePackages $matches['package']
}

# Handles upgrade / uninstall package names
"^upgrade\s+(?<package>[^-\s]*)$" {
"^upgrade\s+(?<package>[^\.][^-\s]*)$" {
chocoLocalPackagesUpgrade $matches['package']
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ param(

Write-Debug "Running 'Start-ChocolateyProcessAsAdmin' with exeToRun:`'$exeToRun`', statements: `'$statements`' ";

try{
if ($exeToRun -ne $null) { $exeToRun = $exeToRun -replace "`0", "" }
if ($statements -ne $null) { $statements = $statements -replace "`0", "" }
} catch {
Write-Debug "Removing null characters resulted in an error - $($_.Exception.Message)"
}

$wrappedStatements = $statements
if ($wrappedStatements -eq $null) { $wrappedStatements = ''}

Expand Down Expand Up @@ -126,10 +133,14 @@ Elevating Permissions and running [`"$exeToRun`" $wrappedStatements]. This may t

Write-Debug $dbgMessage

$exeIsTextFile = [System.IO.Path]::GetFullPath($exeToRun) + ".istext"
if (([System.IO.File]::Exists($exeIsTextFile))) {
Set-PowerShellExitCode 4
throw "The file was a text file but is attempting to be run as an executable - '$exeToRun'"
try {
$exeIsTextFile = [System.IO.Path]::GetFullPath($exeToRun) + ".istext"
if (([System.IO.File]::Exists($exeIsTextFile))) {
Set-PowerShellExitCode 4
throw "The file was a text file but is attempting to be run as an executable - '$exeToRun'"
}
} catch {
Write-Debug "Unable to detect whether the file is a text file or not - $($_.Exception.Message)"
}

if ($exeToRun -eq 'msiexec' -or $exeToRun -eq 'msiexec.exe') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ param(
if ((Test-Path -path $zipContentFile)) {
$zipContentFile
$zipContents=get-content $zipContentFile
foreach ($fileInZip in $zipContents) {
remove-item -Path "$fileInZip" -ErrorAction SilentlyContinue -Recurse -Force
foreach ($fileInZip in $zipContents) {
if ($fileInZip -ne $null -and $fileInZip.Trim() -ne '') {
Remove-Item -Path "$fileInZip" -ErrorAction SilentlyContinue -Recurse -Force
}
}
}
}
Binary file modified src/chocolatey.resources/tools/7z.dll
Binary file not shown.
Binary file modified src/chocolatey.resources/tools/7z.exe
Binary file not shown.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static class ApplicationParameters
public static readonly string ChocolateyToolsLocationEnvironmentVariableName = "ChocolateyToolsLocation";
public static readonly string ChocolateyPackageInstallLocationEnvironmentVariableName = "ChocolateyPackageInstallLocation";
public static readonly string ChocolateyPackageInstallerTypeEnvironmentVariableName = "ChocolateyInstallerType";
public static readonly string ChocolateyPackageExitCodeEnvironmentVariableName = "ChocolateyExitCode";

public static class Environment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void reset_environment_variables(ChocolateyConfiguration config)
{
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyPackageInstallLocationEnvironmentVariableName, null);
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyPackageInstallerTypeEnvironmentVariableName, null);
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyPackageExitCodeEnvironmentVariableName, null);
}

public static void set_environment_variables(ChocolateyConfiguration config)
Expand Down Expand Up @@ -198,12 +199,14 @@ public static void update_environment_variables()

private static IDictionary convert_to_case_insensitive_dictionary(IDictionary originalDictionary)
{
return new Hashtable(originalDictionary, StringComparer.InvariantCultureIgnoreCase);
if (originalDictionary == null) return new Hashtable(new Dictionary<string, string>(), StringComparer.OrdinalIgnoreCase);

return new Hashtable(originalDictionary, StringComparer.OrdinalIgnoreCase);
}

private static void refresh_environment_variables(IDictionary environmentVariables)
{
foreach (DictionaryEntry variable in environmentVariables)
foreach (DictionaryEntry variable in environmentVariables.or_empty_list_if_null())
{
Environment.SetEnvironmentVariable(variable.Key.to_string(), variable.Value.to_string());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ private void uninstall_cleanup(ChocolateyConfiguration config, PackageResult pac

if (config.Force)
{
var packageDirectory = _fileSystem.combine_paths(packageResult.InstallLocation);
var packageDirectory = packageResult.InstallLocation;

if (string.IsNullOrWhiteSpace(packageDirectory) || !_fileSystem.directory_exists(packageDirectory)) return;

Expand Down Expand Up @@ -1010,7 +1010,7 @@ private void move_bad_package_to_failure_location(PackageResult packageResult)
{
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackageFailuresLocation);

if (packageResult.InstallLocation != null && _fileSystem.directory_exists(packageResult.InstallLocation))
if (!string.IsNullOrWhiteSpace(packageResult.InstallLocation) && _fileSystem.directory_exists(packageResult.InstallLocation))
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.move_directory(packageResult.InstallLocation, packageResult.InstallLocation.Replace(ApplicationParameters.PackagesLocation, ApplicationParameters.PackageFailuresLocation)),
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 @@ -328,7 +328,7 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu

//todo: handle all

SemanticVersion version = config.Version != null ? new SemanticVersion(config.Version) : null;
SemanticVersion version = !string.IsNullOrWhiteSpace(config.Version) ? new SemanticVersion(config.Version) : null;
if (config.Force) config.AllowDowngrade = true;

IList<string> packageNames = config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().ToList();
Expand Down Expand Up @@ -466,6 +466,7 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
this.Log().Error(ChocolateyLoggers.Important, logMessage);
var errorResult = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, version.to_string(), null));
errorResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
if (errorResult.ExitCode == 0) errorResult.ExitCode = 1;
if (continueAction != null) continueAction.Invoke(errorResult);
}
}
Expand Down Expand Up @@ -513,7 +514,7 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackagesLocation);
var packageInstalls = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);

SemanticVersion version = config.Version != null ? new SemanticVersion(config.Version) : null;
SemanticVersion version = !string.IsNullOrWhiteSpace(config.Version) ? new SemanticVersion(config.Version) : null;
if (config.Force) config.AllowDowngrade = true;

var packageManager = NugetCommon.GetPackageManager(
Expand Down Expand Up @@ -744,6 +745,7 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
var logMessage = "{0} not upgraded. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, ex.Message);
this.Log().Error(ChocolateyLoggers.Important, logMessage);
packageResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
if (packageResult.ExitCode == 0) packageResult.ExitCode = 1;
if (continueAction != null) continueAction.Invoke(packageResult);
}
}
Expand Down Expand Up @@ -1176,6 +1178,7 @@ public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfi
this.Log().Error(ChocolateyLoggers.Important, logMessage);
var result = packageUninstalls.GetOrAdd(packageVersion.Id.to_lower() + "." + packageVersion.Version.to_string(), new PackageResult(packageVersion, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, packageVersion.Id)));
result.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
if (result.ExitCode == 0) result.ExitCode = 1;
// do not call continueAction - will result in multiple passes
}
}
Expand Down Expand Up @@ -1280,7 +1283,7 @@ private void set_package_names_if_all_is_specified(ChocolateyConfiguration confi
if (!string.IsNullOrWhiteSpace(config.UpgradeCommand.PackageNamesToSkip))
{
var packagesToSkip = config.UpgradeCommand.PackageNamesToSkip
.Split(',')
.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries)
.Where(item => !string.IsNullOrWhiteSpace(item))
.Select(p => p.trim_safe())
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura
Environment.SetEnvironmentVariable("CacheChecksumType_{0}".format_with(urlKey), "sha512");
}
}

}

private ResolveEventHandler _handler = null;
Expand Down Expand Up @@ -480,7 +479,10 @@ private System.Reflection.Assembly attempt_version_load(AssemblyName requestedAs
}
catch (Exception ex)
{
if (requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) return null;

this.Log().Debug(ChocolateyLoggers.Verbose, "Attempting to load assembly {0} failed:{1} {2}".format_with(requestedAssembly.Name, Environment.NewLine, ex.Message.escape_curly_braces()));

return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static string prompt_for_confirmation(string prompt, IEnumerable<string>
c => c.Count() > 0,
(name, value) => { throw new ApplicationException("No choices passed in. Please ensure you pass choices"); });

if (defaultChoice != null)
if (!string.IsNullOrWhiteSpace(defaultChoice))
{
Ensure
.that(() => choices)
Expand Down Expand Up @@ -117,7 +117,7 @@ public static string prompt_for_confirmation(string prompt, IEnumerable<string>
var selection = timeoutInSeconds == 0 ? Console.ReadLine() : Console.ReadLine(timeoutInSeconds * 1000);
if (shortPrompt) Console.WriteLine();

if (string.IsNullOrWhiteSpace(selection) && defaultChoice != null)
if (string.IsNullOrWhiteSpace(selection) && !string.IsNullOrWhiteSpace(defaultChoice))
{
"chocolatey".Log().Info(ChocolateyLoggers.LogFileOnly, "Choosing default choice of '{0}'".format_with(defaultChoice.escape_curly_braces()));
return defaultChoice;
Expand Down
6 changes: 6 additions & 0 deletions src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ private static IEnvironment Environment

public string combine_paths(string leftItem, params string[] rightItems)
{
if (leftItem == null) throw new ApplicationException("Path to combine cannot be empty.");

var combinedPath = Platform.get_platform() == PlatformType.Windows ? leftItem : leftItem.Replace('\\', '/');
foreach (var rightItem in rightItems)
{
Expand Down Expand Up @@ -166,11 +168,15 @@ public string get_current_assembly_path()

public IEnumerable<string> get_files(string directoryPath, string pattern = "*.*", SearchOption option = SearchOption.TopDirectoryOnly)
{
if (string.IsNullOrWhiteSpace(directoryPath)) return new List<string>();

return Directory.EnumerateFiles(directoryPath, pattern, option);
}

public IEnumerable<string> get_files(string directoryPath, string[] extensions, SearchOption option = SearchOption.TopDirectoryOnly)
{
if (string.IsNullOrWhiteSpace(directoryPath)) return new List<string>();

return Directory.EnumerateFiles(directoryPath, "*.*", option)
.Where(f => extensions.Any(x => f.EndsWith(x, StringComparison.OrdinalIgnoreCase)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void configure(string outputDirectory = null)

XmlConfigurator.Configure(xmlConfigStream);

if (outputDirectory != null)
if (!string.IsNullOrWhiteSpace(outputDirectory))
{
set_file_appender(outputDirectory);
}
Expand Down Expand Up @@ -85,8 +85,8 @@ private static void set_file_appender(string outputDirectory)
Layout = layout,
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxFileSize = 1024 * 1024,
MaxSizeRollBackups = 10,
MaxFileSize = 1024 * 1024 * 10,
MaxSizeRollBackups = 50,
LockingModel = new FileAppender.MinimalLock(),
};
app.ActivateOptions();
Expand All @@ -98,8 +98,8 @@ private static void set_file_appender(string outputDirectory)
Layout = layout,
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxFileSize = 1024 * 1024,
MaxSizeRollBackups = 10,
MaxFileSize = 1024 * 1024 * 10,
MaxSizeRollBackups = 50,
LockingModel = new FileAppender.MinimalLock(),

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override Dictionary<string, PSObject> Prompt(string caption, string messa
private static string[] get_hotkey_and_label(string input)
{
var result = new[] { String.Empty, String.Empty };
string[] fragments = input.Split('&');
string[] fragments = input.Split(new char[] {'&'}, StringSplitOptions.RemoveEmptyEntries);
if (fragments.Length == 2)
{
if (fragments[1].Length > 0) result[0] = fragments[1][0].to_string().ToUpper(CultureInfo.CurrentCulture);
Expand Down
1 change: 0 additions & 1 deletion src/chocolatey/infrastructure/tokens/TokenReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace chocolatey.infrastructure.tokens
{
using System.Collections.Generic;
using System.Net.Mime;
using System.Reflection;
using System.Text.RegularExpressions;

Expand Down

0 comments on commit 8843bd7

Please sign in to comment.