diff --git a/src/Building/UnixBuild.php b/src/Building/UnixBuild.php index 031582d2..ef05661e 100644 --- a/src/Building/UnixBuild.php +++ b/src/Building/UnixBuild.php @@ -26,10 +26,6 @@ /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ final class UnixBuild implements Build { - private const PHPIZE_TIMEOUT_SECS = 60; // 1 minute - private const CONFIGURE_TIMEOUT_SECS = 120; // 2 minutes - private const MAKE_TIMEOUT_SECS = null; // unlimited - /** {@inheritDoc} */ public function __invoke( DownloadedPackage $downloadedPackage, @@ -137,8 +133,7 @@ private function phpize( Process::run( $phpizeCommand, $downloadedPackage->extractedSourcePath, - self::PHPIZE_TIMEOUT_SECS, - $outputCallback, + outputCallback: $outputCallback, ); } @@ -162,8 +157,7 @@ private function configure( Process::run( $configureCommand, $downloadedPackage->extractedSourcePath, - self::CONFIGURE_TIMEOUT_SECS, - $outputCallback, + outputCallback: $outputCallback, ); } @@ -195,8 +189,7 @@ private function make( Process::run( $makeCommand, $downloadedPackage->extractedSourcePath, - self::MAKE_TIMEOUT_SECS, - $outputCallback, + outputCallback: $outputCallback, ); } @@ -231,8 +224,7 @@ private function cleanup( Process::run( $phpizeCleanCommand, $downloadedPackage->extractedSourcePath, - self::PHPIZE_TIMEOUT_SECS, - $outputCallback, + outputCallback: $outputCallback, ); $io->write('Build files cleaned up.'); diff --git a/src/ComposerIntegration/PhpBinaryPathBasedPlatformRepository.php b/src/ComposerIntegration/PhpBinaryPathBasedPlatformRepository.php index 7dd5d505..15d1de73 100644 --- a/src/ComposerIntegration/PhpBinaryPathBasedPlatformRepository.php +++ b/src/ComposerIntegration/PhpBinaryPathBasedPlatformRepository.php @@ -124,7 +124,7 @@ private function packageForExtension(string $name, string $prettyVersion): Compl private function detectLibraryWithPkgConfig(string $alias, string $library): void { try { - $pkgConfigResult = Process::run(['pkg-config', '--print-provides', '--print-errors', $library], timeout: 30); + $pkgConfigResult = Process::run(['pkg-config', '--print-provides', '--print-errors', $library]); } catch (ProcessFailedException) { return; } diff --git a/src/File/SudoCreate.php b/src/File/SudoCreate.php index 9a58c003..4f95bcf6 100644 --- a/src/File/SudoCreate.php +++ b/src/File/SudoCreate.php @@ -51,7 +51,7 @@ public static function file(string $filename): void } try { - Process::run([Sudo::find(), 'touch', $filename]); + Process::run([Sudo::find(), 'touch', $filename], timeout: Process::SHORT_TIMEOUT); } catch (ProcessFailedException $processFailedException) { throw FailedToCreateFile::fromSudoTouchProcessFailed($filename, $processFailedException); } diff --git a/src/File/SudoFilePut.php b/src/File/SudoFilePut.php index 98a24119..c9fa6e34 100644 --- a/src/File/SudoFilePut.php +++ b/src/File/SudoFilePut.php @@ -66,7 +66,7 @@ private static function writeWithSudo(string $filename, string $content): void self::copyOwnership($filename, $tempFilename); } - Process::run([Sudo::find(), 'mv', $tempFilename, $filename]); + Process::run([Sudo::find(), 'mv', $tempFilename, $filename], timeout: Process::SHORT_TIMEOUT); } /** @@ -77,18 +77,18 @@ private static function copyOwnership(string $sourceFile, string $targetFile): v { try { // GNU chmod supports `--reference`, so try this first - Process::run([Sudo::find(), 'chmod', '--reference=' . $sourceFile, $targetFile]); + Process::run([Sudo::find(), 'chmod', '--reference=' . $sourceFile, $targetFile], timeout: Process::SHORT_TIMEOUT); return; } catch (ProcessFailedException) { // Fall back to using `stat` to determine uid/gid try { // Try using GNU stat (-c) first - $userAndGroup = Process::run(['stat', '-c', '%u:%g', $sourceFile], timeout: 2); + $userAndGroup = Process::run(['stat', '-c', '%u:%g', $sourceFile]); } catch (ProcessFailedException) { try { // Fall back to using OSX stat (-f) - $userAndGroup = Process::run(['stat', '-f', '%u:%g', $sourceFile], timeout: 2); + $userAndGroup = Process::run(['stat', '-f', '%u:%g', $sourceFile]); } catch (ProcessFailedException) { return; } @@ -98,7 +98,7 @@ private static function copyOwnership(string $sourceFile, string $targetFile): v return; } - Process::run([Sudo::find(), 'chown', $userAndGroup, $targetFile]); + Process::run([Sudo::find(), 'chown', $userAndGroup, $targetFile], timeout: Process::SHORT_TIMEOUT); } } } diff --git a/src/File/SudoUnlink.php b/src/File/SudoUnlink.php index 1cfe33a6..0e158ad4 100644 --- a/src/File/SudoUnlink.php +++ b/src/File/SudoUnlink.php @@ -47,7 +47,7 @@ public static function singleFile(string $filename): void } try { - Process::run([Sudo::find(), 'rm', $filename]); + Process::run([Sudo::find(), 'rm', $filename], timeout: Process::SHORT_TIMEOUT); } catch (ProcessFailedException $processFailedException) { throw FailedToUnlinkFile::fromSudoRmProcessFailed($filename, $processFailedException); } diff --git a/src/Installing/Ini/OndrejPhpenmod.php b/src/Installing/Ini/OndrejPhpenmod.php index d0320901..62c2b256 100644 --- a/src/Installing/Ini/OndrejPhpenmod.php +++ b/src/Installing/Ini/OndrejPhpenmod.php @@ -166,7 +166,7 @@ static function () use ($needSudo, $phpenmodPath, $targetPlatform, $downloadedPa array_unshift($processArgs, Sudo::find()); } - Process::run($processArgs); + Process::run($processArgs, timeout: Process::SHORT_TIMEOUT); return true; } catch (ProcessFailedException $processFailedException) { diff --git a/src/Installing/InstallForPhpProject/InstallSelectedPackage.php b/src/Installing/InstallForPhpProject/InstallSelectedPackage.php index c93b54c0..86e682df 100644 --- a/src/Installing/InstallForPhpProject/InstallSelectedPackage.php +++ b/src/Installing/InstallForPhpProject/InstallSelectedPackage.php @@ -60,8 +60,7 @@ static function (string $value, string $key) use (&$process): void { Process::run( $process, getcwd(), - null, - static function (string $outOrErr, string $message) use ($io): void { + outputCallback: static function (string $outOrErr, string $message) use ($io): void { if ($outOrErr === \Symfony\Component\Process\Process::ERR) { $io->writeError(' > ' . $message); diff --git a/src/Installing/UninstallUsingUnlink.php b/src/Installing/UninstallUsingUnlink.php index ea11f9d4..8ea4e228 100644 --- a/src/Installing/UninstallUsingUnlink.php +++ b/src/Installing/UninstallUsingUnlink.php @@ -46,7 +46,7 @@ public function __invoke(Package $package): BinaryFile // If the target directory isn't writable, or a .so file already exists and isn't writable, try to use sudo if (file_exists($expectedBinaryFile->filePath) && ! is_writable($expectedBinaryFile->filePath) && Sudo::exists()) { - Process::run([Sudo::find(), 'rm', $expectedBinaryFile->filePath]); + Process::run([Sudo::find(), 'rm', $expectedBinaryFile->filePath], timeout: Process::SHORT_TIMEOUT); // Removal worked, bail out if (! file_exists($expectedBinaryFile->filePath)) { diff --git a/src/SelfManage/Verify/GithubCliAttestationVerification.php b/src/SelfManage/Verify/GithubCliAttestationVerification.php index f3803929..6f0dc746 100644 --- a/src/SelfManage/Verify/GithubCliAttestationVerification.php +++ b/src/SelfManage/Verify/GithubCliAttestationVerification.php @@ -19,9 +19,8 @@ /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ final class GithubCliAttestationVerification implements VerifyPiePhar { - private const GH_CLI_NAME = 'gh'; - private const GH_ATTESTATION_COMMAND = 'attestation'; - private const GH_VERIFICATION_TIMEOUT = 30; + private const GH_CLI_NAME = 'gh'; + private const GH_ATTESTATION_COMMAND = 'attestation'; public function __construct(private readonly ExecutableFinder $executableFinder) { @@ -37,7 +36,7 @@ public function verify(ReleaseMetadata $releaseMetadata, BinaryFile $pharFilenam // Try to use `gh attestation --help` to ensure it is not an old `gh` cli version try { - Process::run([$gh, self::GH_ATTESTATION_COMMAND, '--help'], null, self::GH_VERIFICATION_TIMEOUT); + Process::run([$gh, self::GH_ATTESTATION_COMMAND, '--help']); } catch (ProcessFailedException $attestationCommandCheck) { if (str_starts_with($attestationCommandCheck->getProcess()->getErrorOutput(), sprintf('unknown command "%s" for "%s"', self::GH_ATTESTATION_COMMAND, self::GH_CLI_NAME))) { throw GithubCliNotAvailable::withMissingAttestationCommand(self::GH_CLI_NAME); @@ -60,7 +59,7 @@ public function verify(ReleaseMetadata $releaseMetadata, BinaryFile $pharFilenam ); try { - Process::run($verificationCommand, null, self::GH_VERIFICATION_TIMEOUT); + Process::run($verificationCommand); } catch (ProcessFailedException $processFailedException) { throw FailedToVerifyRelease::fromGhCliFailure($releaseMetadata, $processFailedException); } diff --git a/src/Util/Process.php b/src/Util/Process.php index 342107d8..329ce5f2 100644 --- a/src/Util/Process.php +++ b/src/Util/Process.php @@ -12,6 +12,9 @@ /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ final class Process { + public const NO_TIMEOUT = null; + public const SHORT_TIMEOUT = 10; + private function __construct() { } @@ -33,7 +36,7 @@ private function __construct() public static function run( array $command, string|null $workingDirectory = null, - int|null $timeout = 5, + int|null $timeout = self::NO_TIMEOUT, callable|null $outputCallback = null, ): string { return trim((new SymfonyProcess($command, $workingDirectory, timeout: $timeout)) diff --git a/test/install-bundled-php-exts.php b/test/install-bundled-php-exts.php index 29135253..b1bf2a81 100644 --- a/test/install-bundled-php-exts.php +++ b/test/install-bundled-php-exts.php @@ -61,8 +61,8 @@ static function (PackageInterface $package) use ($phpVersionConstraint): bool { } } -echo Process::run([$phpBinaryPath->phpBinaryPath, '-m'], timeout: 60); -echo Process::run(['bin/pie', 'show', '--with-php-config=' . $phpBinaryPath->phpConfigPath()], timeout: 60); +echo Process::run([$phpBinaryPath->phpBinaryPath, '-m']); +echo Process::run(['bin/pie', 'show', '--with-php-config=' . $phpBinaryPath->phpConfigPath()]); if ($anyFailures) { exit(1); diff --git a/test/unit/ComposerIntegration/PhpBinaryPathBasedPlatformRepositoryTest.php b/test/unit/ComposerIntegration/PhpBinaryPathBasedPlatformRepositoryTest.php index 64716ed3..fa38aec8 100644 --- a/test/unit/ComposerIntegration/PhpBinaryPathBasedPlatformRepositoryTest.php +++ b/test/unit/ComposerIntegration/PhpBinaryPathBasedPlatformRepositoryTest.php @@ -188,7 +188,7 @@ public static function installedLibraries(): array ], static function (array $pkg): bool { try { - Process::run(['pkg-config', '--print-provides', '--print-errors', $pkg[1]], timeout: 30); + Process::run(['pkg-config', '--print-provides', '--print-errors', $pkg[1]]); return true; } catch (ProcessFailedException) {