Page MenuHomePhabricator

D10248.id24662.diff
No OneTemporary

D10248.id24662.diff

diff --git a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
--- a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
+++ b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
@@ -36,18 +36,48 @@
$argv = func_get_args();
- // This assumes there's a UNIX shell living at the other
- // end of the connection, which isn't the case for Windows machines.
- if ($this->getConfig('platform') !== 'windows') {
- $argv = $this->applyWorkingDirectoryToArgv($argv);
- }
+ if ($this->getConfig('platform') === 'windows') {
+ // Handle Windows by executing the command under PowerShell.
+ $command = id(new PhutilCommandString($argv))
+ ->setPowershell(true);
- $full_command = call_user_func_array('csprintf', $argv);
+ if (strpos($command, 'mkdir') === false) {
+ throw new Exception($command);
+ }
- if ($this->getConfig('platform') === 'windows') {
- // On Windows platforms we need to execute cmd.exe explicitly since
- // most commands are not really executables.
- $full_command = 'C:\\Windows\\system32\\cmd.exe /C '.$full_command;
+ $change_directory = '';
+ if ($this->getWorkingDirectory() !== null) {
+ $change_directory .= 'cd '.$this->getWorkingDirectory();
+ }
+
+ $script = <<<EOF
+$change_directory
+$command
+if (\$LastExitCode -ne 0) {
+ exit \$LastExitCode
+}
+EOF;
+
+ // When Microsoft says "Unicode" they don't mean UTF-8.
+ $script = mb_convert_encoding($script, 'UTF-16LE');
+
+ $script = base64_encode($script);
+
+ $powershell =
+ 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe';
+ $powershell .=
+ ' -ExecutionPolicy Bypass'.
+ ' -NonInteractive'.
+ ' -InputFormat Text'.
+ ' -OutputFormat Text'.
+ ' -EncodedCommand '.$script;
+
+ $full_command = $powershell;
+ } else {
+ // Handle UNIX by executing under the native shell.
+ $argv = $this->applyWorkingDirectoryToArgv($argv);
+
+ $full_command = call_user_func_array('csprintf', $argv);
}
$command_timeout = '';
diff --git a/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php b/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php
--- a/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php
+++ b/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php
@@ -25,6 +25,8 @@
$settings = $this->getSettings();
$variables = $build_target->getVariables();
+ $variables['quotetest'] = '"``""###""\'\'"""\'"\'"\'';
+
$command = $this->mergeVariables(
'vcsprintf',
$settings['command'],
@@ -88,6 +90,9 @@
'name' => pht('Command'),
'type' => 'text',
'required' => true,
+ 'caption' => pht(
+ 'Under Windows, this is executed under PowerShell.'.
+ 'Under UNIX, this is executed using the user\'s shell.'),
),
'hostartifact' => array(
'name' => pht('Host'),

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 24, 1:21 AM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8923822
Default Alt Text
D10248.id24662.diff (3 KB)

Event Timeline