diff --git a/src/Composer/Package/Archiver/ArchiveManager.php b/src/Composer/Package/Archiver/ArchiveManager.php index 679d52586..ff8e2da95 100644 --- a/src/Composer/Package/Archiver/ArchiveManager.php +++ b/src/Composer/Package/Archiver/ArchiveManager.php @@ -76,18 +76,18 @@ class ArchiveManager // Directory used to download the sources $filesystem = new Filesystem(); $packageName = $package->getUniqueName(); - $sources = sys_get_temp_dir().'/composer_archiver/'.$packageName; - $filesystem->ensureDirectoryExists($sources); + $sourcePath = sys_get_temp_dir().'/composer_archiver/'.$packageName; + $filesystem->ensureDirectoryExists($sourcePath); // Archive filename $target = $targetDir.'/'.$packageName.'.'.$format; $filesystem->ensureDirectoryExists(dirname($target)); // Download sources - $this->downloadManager->download($package, $sources, true); + $this->downloadManager->download($package, $sourcePath, true); // Create the archive $sourceRef = $package->getSourceReference(); - $usableArchiver->archive($sources, $target, $format, $sourceRef); + $usableArchiver->archive($sourcePath, $target, $format, $sourceRef); } } diff --git a/src/Composer/Package/Archiver/ArchiverInterface.php b/src/Composer/Package/Archiver/ArchiverInterface.php index 596402154..38eb2cdd3 100644 --- a/src/Composer/Package/Archiver/ArchiverInterface.php +++ b/src/Composer/Package/Archiver/ArchiverInterface.php @@ -23,7 +23,7 @@ interface ArchiverInterface /** * Create an archive from the sources. * - * @param string $source The sources directory + * @param string $sources The sources directory * @param string $target The target file * @param string $format The format used for archive * @param string $sourceRef The reference of the source to archive or null diff --git a/src/Composer/Package/Archiver/GitArchiver.php b/src/Composer/Package/Archiver/GitArchiver.php index 922d9af19..c18ab37a5 100644 --- a/src/Composer/Package/Archiver/GitArchiver.php +++ b/src/Composer/Package/Archiver/GitArchiver.php @@ -42,7 +42,7 @@ class GitArchiver implements ArchiverInterface 'git archive --format %s --output %s %s', $format, escapeshellarg($target), - $sourceRef + escapeshellarg($sourceRef) ); $exitCode = $this->process->execute($command, $output, $sources); diff --git a/src/Composer/Package/Archiver/MercurialArchiver.php b/src/Composer/Package/Archiver/MercurialArchiver.php index 9a67694df..b21750b45 100644 --- a/src/Composer/Package/Archiver/MercurialArchiver.php +++ b/src/Composer/Package/Archiver/MercurialArchiver.php @@ -38,7 +38,7 @@ class MercurialArchiver implements ArchiverInterface $command = sprintf( 'hg archive --rev %s --type %s %s', - $sourceRef, + escapeshellarg($sourceRef), $format, escapeshellarg($target) ); diff --git a/src/Composer/Package/Archiver/PharArchiver.php b/src/Composer/Package/Archiver/PharArchiver.php index 02aaa0ab3..24e376d2a 100644 --- a/src/Composer/Package/Archiver/PharArchiver.php +++ b/src/Composer/Package/Archiver/PharArchiver.php @@ -30,29 +30,9 @@ class PharArchiver implements ArchiverInterface * {@inheritdoc} */ public function archive($sources, $target, $format, $sourceRef = null) - { - $this->createPharArchive($sources, $target, static::$formats[$format]); - } - - /** - * {@inheritdoc} - */ - public function supports($format, $sourceType) - { - return isset(static::$formats[$format]); - } - - /** - * Create a PHAR archive. - * - * @param string $sources Path of the directory to archive - * @param string $target Path of the file archive to create - * @param int $format Format of the archive - */ - protected function createPharArchive($sources, $target, $format) { try { - $phar = new \PharData($target, null, null, $format); + $phar = new \PharData($target, null, null, static::$formats[$format]); $phar->buildFromDirectory($sources); } catch (\UnexpectedValueException $e) { $message = sprintf("Could not create archive '%s' from '%s': %s", @@ -64,4 +44,12 @@ class PharArchiver implements ArchiverInterface throw new \RuntimeException($message, $e->getCode(), $e); } } + + /** + * {@inheritdoc} + */ + public function supports($format, $sourceType) + { + return isset(static::$formats[$format]); + } } diff --git a/tests/Composer/Test/Package/Archiver/ArchiverTest.php b/tests/Composer/Test/Package/Archiver/ArchiverTest.php index 4b8d91c51..62e4bb914 100644 --- a/tests/Composer/Test/Package/Archiver/ArchiverTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchiverTest.php @@ -57,16 +57,19 @@ abstract class ArchiverTest extends \PHPUnit_Framework_TestCase $result = $this->process->execute('git init -q'); if ($result > 0) { + chdir($currentWorkDir); throw new \RuntimeException('Could not init: '.$this->process->getErrorOutput()); } $result = file_put_contents('b', 'a'); if (false === $result) { + chdir($currentWorkDir); throw new \RuntimeException('Could not save file.'); } $result = $this->process->execute('git add b && git commit -m "commit b" -q'); if ($result > 0) { + chdir($currentWorkDir); throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput()); }