Add handling of ctrl-C on windows for php 7.4+

main
Jordi Boggiano 4 years ago
parent 29761cf78d
commit 396ad87fd0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -367,6 +367,17 @@ EOT
}); });
} }
} }
// handler Ctrl+C for Windows on PHP 7.4+
if (function_exists('sapi_windows_set_ctrl_handler')) {
@mkdir($directory, 0777, true);
if ($realDir = realpath($directory)) {
sapi_windows_set_ctrl_handler(function () use ($realDir) {
$fs = new Filesystem();
$fs->removeDirectory($realDir);
exit(130);
});
}
}
// avoid displaying 9999999-dev as version if dev-master was selected // avoid displaying 9999999-dev as version if dev-master was selected
if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEV_MASTER_ALIAS) { if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEV_MASTER_ALIAS) {

@ -195,10 +195,11 @@ class InstallationManager
} }
}; };
// handler Ctrl+C for unix-like systems $handleInterruptsUnix = function_exists('pcntl_async_signals') && function_exists('pcntl_signal');
$handleInterrupts = function_exists('pcntl_async_signals') && function_exists('pcntl_signal'); $handleInterruptsWindows = function_exists('sapi_windows_set_ctrl_handler');
$prevHandler = null; $prevHandler = null;
if ($handleInterrupts) { $windowsHandler = null;
if ($handleInterruptsUnix) {
pcntl_async_signals(true); pcntl_async_signals(true);
$prevHandler = pcntl_signal_get_handler(SIGINT); $prevHandler = pcntl_signal_get_handler(SIGINT);
pcntl_signal(SIGINT, function ($sig) use ($runCleanup, $prevHandler) { pcntl_signal(SIGINT, function ($sig) use ($runCleanup, $prevHandler) {
@ -211,6 +212,14 @@ class InstallationManager
exit(130); exit(130);
}); });
} }
if ($handleInterruptsWindows) {
$windowsHandler = function () use ($runCleanup) {
$runCleanup();
exit(130);
};
sapi_windows_set_ctrl_handler($windowsHandler);
}
try { try {
foreach ($operations as $index => $operation) { foreach ($operations as $index => $operation) {
@ -317,16 +326,22 @@ class InstallationManager
} catch (\Exception $e) { } catch (\Exception $e) {
$runCleanup(); $runCleanup();
if ($handleInterrupts) { if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler); pcntl_signal(SIGINT, $prevHandler);
} }
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
throw $e; throw $e;
} }
if ($handleInterrupts) { if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler); pcntl_signal(SIGINT, $prevHandler);
} }
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
// do a last write so that we write the repository even if nothing changed // do a last write so that we write the repository even if nothing changed
// as that can trigger an update of some files like InstalledVersions.php if // as that can trigger an update of some files like InstalledVersions.php if

Loading…
Cancel
Save