Skip to content

Commit

Permalink
Make sure proc_open is not required for basic installs, refs #9253
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Aug 18, 2021
1 parent d6f4111 commit 60fe670
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Composer/Downloader/ZipDownloader.php
Expand Up @@ -54,14 +54,24 @@ public function download(PackageInterface $package, $path, PackageInterface $pre
}
}

$procOpenMissing = false;
if (!function_exists('proc_open')) {
self::$unzipCommands = array();
$procOpenMissing = true;
}

if (null === self::$hasZipArchive) {
self::$hasZipArchive = class_exists('ZipArchive');
}

if (!self::$hasZipArchive && !self::$unzipCommands) {
// php.ini path is added to the error message to help users find the correct file
$iniMessage = IniHelper::getMessage();
$error = "The zip extension and unzip/7z commands are both missing, skipping.\n" . $iniMessage;
if ($procOpenMissing) {
$error = "The zip extension is missing and unzip/7z commands cannot be called as proc_open is disabled, skipping.\n" . $iniMessage;
} else {
$error = "The zip extension and unzip/7z commands are both missing, skipping.\n" . $iniMessage;
}

throw new \RuntimeException($error);
}
Expand All @@ -70,9 +80,15 @@ public function download(PackageInterface $package, $path, PackageInterface $pre
self::$isWindows = Platform::isWindows();

if (!self::$isWindows && !self::$unzipCommands) {
$this->io->writeError("<warning>As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.</warning>");
$this->io->writeError("<warning>This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.</warning>");
$this->io->writeError("<warning>Installing 'unzip' or '7z' may remediate them.</warning>");
if ($procOpenMissing) {
$this->io->writeError("<warning>proc_open is disabled so 'unzip' and '7z' commands cannot be used, zip files are being unpacked using the PHP zip extension.</warning>");
$this->io->writeError("<warning>This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.</warning>");
$this->io->writeError("<warning>Enabling proc_open and installing 'unzip' or '7z' may remediate them.</warning>");
} else {
$this->io->writeError("<warning>As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.</warning>");
$this->io->writeError("<warning>This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.</warning>");
$this->io->writeError("<warning>Installing 'unzip' or '7z' may remediate them.</warning>");
}
}
}

Expand Down

0 comments on commit 60fe670

Please sign in to comment.