Skip to content

Commit

Permalink
Copy wrapper exe outside the archive on Windows in case of PHARs
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Apr 8, 2018
1 parent e0c753c commit b795d20
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/Internal/Windows/Runner.php
Expand Up @@ -29,12 +29,30 @@ final class Runner implements ProcessRunner {
? BIN_DIR . '\\windows\\ProcessWrapper64.exe'
: BIN_DIR . '\\windows\\ProcessWrapper.exe';

private static $pharWrapperPath;

private $socketConnector;

private function makeCommand(string $workingDirectory): string {
$wrapperPath = self::WRAPPER_EXE_PATH;

// We can't execute the exe from within the PHAR, so copy it out...
if (strncmp($wrapperPath, "phar://", 7) === 0) {
if (self::$pharWrapperPath === null) {
self::$pharWrapperPath = \tempnam(\sys_get_temp_dir(), "amphp-process-wrapper-");
\copy(self::WRAPPER_EXE_PATH, self::$pharWrapperPath);

\register_shutdown_function(static function () {
@\unlink(self::$pharWrapperPath);
});
}

$wrapperPath = self::$pharWrapperPath;
}

$result = \sprintf(
'%s --address=%s --port=%d --token-size=%d',
\escapeshellarg(self::WRAPPER_EXE_PATH),
\escapeshellarg($wrapperPath),
$this->socketConnector->address,
$this->socketConnector->port,
SocketConnector::SECURITY_TOKEN_SIZE
Expand Down

0 comments on commit b795d20

Please sign in to comment.