Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-1042) Ensure-Permissions fails when run as SYSTEM
  (build) ensure build is on .NET 4.0
  (maint) remove test console logging
  (maint) rename searchTerm variable
  (maint) update nuget.core
  (GH-1059) Fix: Unable to change command execution timeout
  (GH-1059) Clean up commandExecutionTimeout setting
  (maint) clean up CacheLocation
  (GH-1202) Allow 0 for infinite timeout
  (GH-1059) Deprecate old config elements
  • Loading branch information
ferventcoder committed Mar 15, 2017
2 parents 224c399 + 3571604 commit 628b4a7
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .uppercut
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<property name="sign.project_with_key" value="true" overwrite="false" />

<!-- Build Features Overrides -->
<property name="microsoft.framework" value="net-4.0" overwrite="false" />
<property name="nant.settings.currentframework" value="net-4.0"/>
<property name="test.framework" value="nunit" overwrite="false" />
<property name="cover.framework" value="opencover" overwrite="false" />

Expand Down
Binary file modified lib/NuGet-Chocolatey/NuGet.Core.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion nuget/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ param(

$defaultInstallPath = "$env:SystemDrive\ProgramData\chocolatey"
try {
$defaultInstallPath = Join-Path [Environment]::GetFolderPath("CommonApplicationData") 'chocolatey'
$defaultInstallPath = Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) 'chocolatey'
} catch {
# keep first setting
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,6 @@ public override void Context()

public override void Because()
{
//MockLogger.LogMessagesToConsole = true;
Results = Service.install_run(Configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ public override void Context()

public override void Because()
{
MockLogger.LogMessagesToConsole = true;
service.run(packageResult, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class when_CommandExecutor_does_not_wait_for_exit : CommandExecutorSpecsB

public override void Because()
{
result = commandExecutor.execute("bob", "args", waitForExitInSeconds: 0);
result = commandExecutor.execute("bob", "args", waitForExitInSeconds: 0, workingDirectory:null, stdOutAction: null, stdErrAction: null, updateProcessPath:false, allowUseWindow: true, waitForExit: false);
}

[Fact]
Expand Down
32 changes: 11 additions & 21 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,18 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi

private static void set_config_items(ChocolateyConfiguration config, ConfigFileSettings configFileSettings, IFileSystem fileSystem)
{
var cacheLocation = set_config_item(ApplicationParameters.ConfigSettings.CacheLocation, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? string.Empty : configFileSettings.CacheLocation, "Cache location if not TEMP folder.");
config.CacheLocation = !string.IsNullOrWhiteSpace(cacheLocation) ? Environment.ExpandEnvironmentVariables(cacheLocation) : fileSystem.combine_paths(fileSystem.get_temp_path(), "chocolatey"); // System.Environment.GetEnvironmentVariable("TEMP");
if (string.IsNullOrWhiteSpace(config.CacheLocation))
{
config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");
}

var originalCommandTimeout = configFileSettings.CommandExecutionTimeoutSeconds;
var commandExecutionTimeoutSeconds = -1;
int.TryParse(
set_config_item(
ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds,
configFileSettings,
originalCommandTimeout == 0 ?
ApplicationParameters.DefaultWaitForExitInSeconds.to_string()
: originalCommandTimeout.to_string(),
"Default timeout for command execution."),
out commandExecutionTimeoutSeconds);
config.CacheLocation = Environment.ExpandEnvironmentVariables(set_config_item(ApplicationParameters.ConfigSettings.CacheLocation, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? string.Empty : configFileSettings.CacheLocation, "Cache location if not TEMP folder."));
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.combine_paths(fileSystem.get_temp_path(), "chocolatey"); // System.Environment.GetEnvironmentVariable("TEMP");
// if it is still empty, use temp in the Chocolatey install directory.
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");

var commandExecutionTimeoutSeconds = 0;
var commandExecutionTimeout = set_config_item(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CommandExecutionTimeoutSeconds.to_string()) ? ApplicationParameters.DefaultWaitForExitInSeconds.to_string() : configFileSettings.CommandExecutionTimeoutSeconds.to_string(), "Default timeout for command execution. '0' for infinite (starting in 0.10.4).");
int.TryParse(commandExecutionTimeout, out commandExecutionTimeoutSeconds);
config.CommandExecutionTimeoutSeconds = commandExecutionTimeoutSeconds;
if (configFileSettings.CommandExecutionTimeoutSeconds <= 0)
if (commandExecutionTimeout != "0" && commandExecutionTimeoutSeconds <= 0)
{
set_config_item(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds, configFileSettings, ApplicationParameters.DefaultWaitForExitInSeconds.to_string(), "Default timeout for command execution.", forceSettingValue: true);
set_config_item(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds, configFileSettings, ApplicationParameters.DefaultWaitForExitInSeconds.to_string(), "Default timeout for command execution. '0' for infinite (starting in 0.10.4).", forceSettingValue: true);
config.CommandExecutionTimeoutSeconds = ApplicationParameters.DefaultWaitForExitInSeconds;
}

Expand Down Expand Up @@ -352,7 +342,7 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
"LimitOutput - Limit the output to essential information",
option => config.RegularOutput = option == null)
.Add("timeout=|execution-timeout=",
"CommandExecutionTimeout (in seconds) - The time to allow a command to finish before timing out. Overrides the default execution timeout in the configuration of {0} seconds.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
"CommandExecutionTimeout (in seconds) - The time to allow a command to finish before timing out. Overrides the default execution timeout in the configuration of {0} seconds. '0' for infinite starting in 0.10.4.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
option =>
{
int timeout = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ namespace chocolatey.infrastructure.app.configuration
[XmlRoot("chocolatey")]
public class ConfigFileSettings
{
[Obsolete("This will be removed in v1 of Chocolatey")]
[XmlElement(ElementName = "cacheLocation")]
public string CacheLocation { get; set; }

[XmlElement(ElementName = "containsLegacyPackageInstalls")]
public bool ContainsLegacyPackageInstalls { get; set; }

[Obsolete("This will be removed in v1 of Chocolatey")]
[XmlElement(ElementName = "commandExecutionTimeoutSeconds")]
public int CommandExecutionTimeoutSeconds { get; set; }

Expand Down
14 changes: 7 additions & 7 deletions src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static int GetCount(ChocolateyConfiguration configuration, ILogger nugetL
private static IQueryable<IPackage> execute_package_search(ChocolateyConfiguration configuration, ILogger nugetLogger)
{
var packageRepository = NugetCommon.GetRemoteRepository(configuration, nugetLogger, new PackageDownloader());
var searchTerm = configuration.Input.to_lower();
var searchTermLower = configuration.Input.to_lower();

// Whether or not the package is remote determines two things:
// 1. Does the repository have a notion of "listed"?
Expand All @@ -57,7 +57,7 @@ private static IQueryable<IPackage> execute_package_search(ChocolateyConfigurati
isRemote = packageRepository is IServiceBasedRepository;
}

IQueryable<IPackage> results = packageRepository.Search(searchTerm, configuration.Prerelease);
IQueryable<IPackage> results = packageRepository.Search(searchTermLower, configuration.Prerelease);


if (configuration.ListCommand.Page.HasValue)
Expand All @@ -67,21 +67,21 @@ private static IQueryable<IPackage> execute_package_search(ChocolateyConfigurati

if (configuration.ListCommand.Exact)
{
results = results.Where(p => p.Id.ToLower() == searchTerm);
results = results.Where(p => p.Id.ToLower() == searchTermLower);
}

if (configuration.ListCommand.ByIdOnly)
{
results = isRemote ?
results.Where(p => p.Id.ToLower().Contains(searchTerm))
: results.Where(p => p.Id.contains(searchTerm, StringComparison.OrdinalIgnoreCase));
results.Where(p => p.Id.ToLower().Contains(searchTermLower))
: results.Where(p => p.Id.contains(searchTermLower, StringComparison.OrdinalIgnoreCase));
}

if (configuration.ListCommand.IdStartsWith)
{
results = isRemote ?
results.Where(p => p.Id.ToLower().StartsWith(searchTerm))
: results.Where(p => p.Id.StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase));
results.Where(p => p.Id.ToLower().StartsWith(searchTermLower))
: results.Where(p => p.Id.StartsWith(searchTermLower, StringComparison.OrdinalIgnoreCase));
}

if (configuration.ListCommand.ApprovedOnly)
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetPush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void push_package(ChocolateyConfiguration config, string nupkgFile
var timeout = TimeSpan.FromSeconds(Math.Abs(config.CommandExecutionTimeoutSeconds));
if (timeout.Seconds <= 0)
{
timeout = TimeSpan.FromMinutes(5); // Default to 5 minutes
timeout = TimeSpan.FromMinutes(300); // Default to 5 hours if there is a zero (infinite) timeout
}
const bool disableBuffering = false;

Expand Down
88 changes: 76 additions & 12 deletions src/chocolatey/infrastructure/commands/CommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public int execute(string process, string arguments, int waitForExitInSeconds)
stdOutAction,
stdErrAction,
updateProcessPath,
allowUseWindow:false
allowUseWindow: false
);
}

Expand All @@ -87,15 +87,39 @@ public int execute(string process, string arguments, int waitForExitInSeconds, s
bool updateProcessPath,
bool allowUseWindow
)
{
return execute(process,
arguments,
waitForExitInSeconds,
workingDirectory,
stdOutAction,
stdErrAction,
updateProcessPath,
allowUseWindow,
waitForExit:true
);
}

public int execute(string process,
string arguments,
int waitForExitInSeconds,
string workingDirectory,
Action<object, DataReceivedEventArgs> stdOutAction,
Action<object, DataReceivedEventArgs> stdErrAction,
bool updateProcessPath,
bool allowUseWindow,
bool waitForExit
)
{
return execute_static(process,
arguments,
waitForExitInSeconds,
file_system.get_directory_name(Assembly.GetExecutingAssembly().Location),
workingDirectory,
stdOutAction,
stdErrAction,
updateProcessPath,
allowUseWindow
allowUseWindow,
waitForExit
);
}

Expand All @@ -107,6 +131,29 @@ bool allowUseWindow
Action<object, DataReceivedEventArgs> stdErrAction,
bool updateProcessPath,
bool allowUseWindow
)
{
return execute_static(process,
arguments,
waitForExitInSeconds,
workingDirectory,
stdOutAction,
stdErrAction,
updateProcessPath,
allowUseWindow,
waitForExit: true
);
}

public static int execute_static(string process,
string arguments,
int waitForExitInSeconds,
string workingDirectory,
Action<object, DataReceivedEventArgs> stdOutAction,
Action<object, DataReceivedEventArgs> stdErrAction,
bool updateProcessPath,
bool allowUseWindow,
bool waitForExit
)
{
int exitCode = -1;
Expand All @@ -121,16 +168,21 @@ bool allowUseWindow
process = "mono";
}

if (string.IsNullOrWhiteSpace(workingDirectory))
{
workingDirectory = file_system.get_directory_name(file_system.get_current_assembly_path());
}

"chocolatey".Log().Debug(() => "Calling command ['\"{0}\" {1}']".format_with(process.escape_curly_braces(), arguments.escape_curly_braces()));

var psi = new ProcessStartInfo(process.remove_surrounding_quotes(), arguments)
{
UseShellExecute = false,
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardError = true,
CreateNoWindow = !allowUseWindow,
WindowStyle = ProcessWindowStyle.Minimized,
WindowStyle = ProcessWindowStyle.Minimized,
};

using (var p = initialize_process())
Expand Down Expand Up @@ -158,20 +210,32 @@ bool allowUseWindow
p.BeginErrorReadLine();
p.BeginOutputReadLine();

if (waitForExitInSeconds > 0)
if (waitForExit || waitForExitInSeconds > 0)
{
var exited = p.WaitForExit((int) TimeSpan.FromSeconds(waitForExitInSeconds).TotalMilliseconds);
if (exited)
if (waitForExitInSeconds > 0)
{
exitCode = p.ExitCode;
var exited = p.WaitForExit((int)TimeSpan.FromSeconds(waitForExitInSeconds).TotalMilliseconds);
if (exited)
{
exitCode = p.ExitCode;
}
else
{
"chocolatey".Log().Warn(ChocolateyLoggers.Important, () => @"Chocolatey timed out waiting for the command to finish. The timeout
specified (or the default value) was '{0}' seconds. Perhaps try a
higher `--execution-timeout`? See `choco -h` for details.".format_with(waitForExitInSeconds));
}
}
else
{
"chocolatey".Log().Warn(ChocolateyLoggers.Important, () => @"Chocolatey timed out waiting for the command to finish. The timeout
specified (or the default value) was '{0}' seconds. Perhaps try a
higher `--execution-timeout`? See `choco -h` for details.".format_with(waitForExitInSeconds));
p.WaitForExit();
exitCode = p.ExitCode;
}
}
else
{
"chocolatey".Log().Debug(ChocolateyLoggers.LogFileOnly, () => @"Started process called but not waiting on exit.");
}
}

"chocolatey".Log().Debug(() => "Command ['\"{0}\" {1}'] exited with '{2}'".format_with(process.escape_curly_braces(), arguments.escape_curly_braces(), exitCode));
Expand Down
14 changes: 13 additions & 1 deletion src/chocolatey/infrastructure/commands/ICommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ bool updateProcessPath
Action<object, DataReceivedEventArgs> stdErrAction,
bool updateProcessPath,
bool allowUseWindow
);
);

int execute(
string process,
string arguments,
int waitForExitInSeconds,
string workingDirectory,
Action<object, DataReceivedEventArgs> stdOutAction,
Action<object, DataReceivedEventArgs> stdErrAction,
bool updateProcessPath,
bool allowUseWindow,
bool waitForExit
);
}
}

0 comments on commit 628b4a7

Please sign in to comment.