Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/Building/UnixBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -137,8 +133,7 @@ private function phpize(
Process::run(
$phpizeCommand,
$downloadedPackage->extractedSourcePath,
self::PHPIZE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
}

Expand All @@ -162,8 +157,7 @@ private function configure(
Process::run(
$configureCommand,
$downloadedPackage->extractedSourcePath,
self::CONFIGURE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
}

Expand Down Expand Up @@ -195,8 +189,7 @@ private function make(
Process::run(
$makeCommand,
$downloadedPackage->extractedSourcePath,
self::MAKE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
}

Expand Down Expand Up @@ -231,8 +224,7 @@ private function cleanup(
Process::run(
$phpizeCleanCommand,
$downloadedPackage->extractedSourcePath,
self::PHPIZE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);

$io->write('<info>Build files cleaned up.</info>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/File/SudoCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/File/SudoFilePut.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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;
}
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/File/SudoUnlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Installing/Ini/OndrejPhpenmod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Installing/UninstallUsingUnlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 4 additions & 5 deletions src/SelfManage/Verify/GithubCliAttestationVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Util/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions test/install-bundled-php-exts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down