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)
{
$composerFile = Zip::findFile($file->getPathname(), 'composer.json');
$composerFile = Zip::findComposerJson($file->getPathname());
if (null === $composerFile) {
return false;

View File

@ -18,15 +18,19 @@ namespace Composer\Util;
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 $filename
*
* @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();
if ($zip->open($pathToZip) !== true) {
return null;
@ -38,7 +42,7 @@ class Zip
return null;
}
$foundFileIndex = self::locateFile($zip, $filename);
$foundFileIndex = self::locateFile($zip, 'composer.json');
if (false === $foundFileIndex) {
$zip->close();
@ -68,7 +72,7 @@ class Zip
$stat = $zip->statIndex($i);
if (strcmp(basename($stat['name']), $filename) === 0) {
$directoryName = dirname($stat['name']);
if ($directoryName == '.') {
if ($directoryName === '.') {
//if composer.json is in root directory
//it has to be the one to use.
return $i;