From 84a7fff2ad654aa12488db6b259221d4b7520038 Mon Sep 17 00:00:00 2001 From: Arne Blankerts Date: Tue, 23 Jul 2019 19:58:32 +0200 Subject: [PATCH] Fix #202 --- src/shared/PharRegistry.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/shared/PharRegistry.php b/src/shared/PharRegistry.php index 108ab8ad..deacc1b0 100644 --- a/src/shared/PharRegistry.php +++ b/src/shared/PharRegistry.php @@ -21,14 +21,11 @@ public function __construct(XmlFile $xmlFile, Directory $pharDirectory) { } public function addPhar(Phar $phar): Phar { - $destinationFile = $this->savePhar($phar->getFile()); + $destinationFile = $this->savePhar($phar); $pharNode = $this->dbFile->createElement('phar'); $pharNode->setAttribute('name', $phar->getName()); $pharNode->setAttribute('version', $phar->getVersion()->getVersionString()); - $pharNode->setAttribute( - 'location', - $this->pharDirectory . \DIRECTORY_SEPARATOR . $phar->getFile()->getFilename() - ); + $pharNode->setAttribute('location', $destinationFile->asString()); $hashNode = $this->dbFile->createElement('hash', Sha1Hash::forContent($phar->getFile()->getContent())->asString()); $hashNode->setAttribute('type', 'sha1'); $pharNode->appendChild($hashNode); @@ -173,16 +170,22 @@ public function getKnownSignatureFingerprints(string $alias): array { return \array_unique($fingerprints); } - private function savePhar(File $pharFile): Filename { - $destination = new Filename($this->getPharDestination($pharFile)); - $pharFile->saveAs($destination); + private function savePhar(Phar $phar): Filename { + $destination = new Filename($this->getPharDestination($phar)); + $phar->getFile()->saveAs($destination); \chmod($destination->asString(), 0755); return $destination; } - private function getPharDestination(File $file): string { - return $this->pharDirectory . \DIRECTORY_SEPARATOR . $file->getFilename(); + private function getPharDestination(Phar $phar): string { + + return sprintf( + '%s/%s-%s.phar', + $this->pharDirectory, + $phar->getName(), + $phar->getVersion()->getVersionString() + ); } private function getFirstMatchingPharNode(string $name, Version $version): ?DOMElement {