1
0
Fork 0

Adjust Zip Util to only find the root composer.json

pull/7994/head
Andreas Schempp 2019-03-01 11:06:03 +01:00
parent 05d6b21785
commit 0d0cb53f31
2 changed files with 9 additions and 5 deletions

View File

@ -83,7 +83,7 @@ class ArtifactRepository extends ArrayRepository implements ConfigurableReposito
private function getComposerInformation(\SplFileInfo $file) private function getComposerInformation(\SplFileInfo $file)
{ {
$composerFile = Zip::findFile($file->getPathname(), 'composer.json'); $composerFile = Zip::findComposerJson($file->getPathname());
if (null === $composerFile) { if (null === $composerFile) {
return false; return false;

View File

@ -18,15 +18,19 @@ namespace Composer\Util;
class Zip class Zip
{ {
/** /**
* Finds the path to a file inside a ZIP archive. * Finds the path to the root composer.json inside a ZIP archive.
* *
* @param string $pathToZip * @param string $pathToZip
* @param string $filename * @param string $filename
* *
* @return string|null * @return string|null
*/ */
public static function findFile($pathToZip, $filename) public static function findComposerJson($pathToZip)
{ {
if (!extension_loaded('zip')) {
throw new \RuntimeException('The Zip Util requires PHP\'s zip extension');
}
$zip = new \ZipArchive(); $zip = new \ZipArchive();
if ($zip->open($pathToZip) !== true) { if ($zip->open($pathToZip) !== true) {
return null; return null;
@ -38,7 +42,7 @@ class Zip
return null; return null;
} }
$foundFileIndex = self::locateFile($zip, $filename); $foundFileIndex = self::locateFile($zip, 'composer.json');
if (false === $foundFileIndex) { if (false === $foundFileIndex) {
$zip->close(); $zip->close();
@ -68,7 +72,7 @@ class Zip
$stat = $zip->statIndex($i); $stat = $zip->statIndex($i);
if (strcmp(basename($stat['name']), $filename) === 0) { if (strcmp(basename($stat['name']), $filename) === 0) {
$directoryName = dirname($stat['name']); $directoryName = dirname($stat['name']);
if ($directoryName == '.') { if ($directoryName === '.') {
//if composer.json is in root directory //if composer.json is in root directory
//it has to be the one to use. //it has to be the one to use.
return $i; return $i;