diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 653015bab..676b2977e 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -366,7 +366,6 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface return $promise->then(function () use ($self, $target, $path, $io) { $promise = $self->install($target, $path, false); - $io->writeError(''); return $promise; }); diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 4cfe616ea..0a0461a4a 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -87,30 +87,9 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter } // Get the transport options with default values - $transportOptions = $package->getTransportOptions() + array('symlink' => null, 'relative' => true); + $transportOptions = $package->getTransportOptions() + array('relative' => true); - // When symlink transport option is null, both symlink and mirror are allowed - $currentStrategy = self::STRATEGY_SYMLINK; - $allowedStrategies = array(self::STRATEGY_SYMLINK, self::STRATEGY_MIRROR); - - $mirrorPathRepos = getenv('COMPOSER_MIRROR_PATH_REPOS'); - if ($mirrorPathRepos) { - $currentStrategy = self::STRATEGY_MIRROR; - } - - if (true === $transportOptions['symlink']) { - $currentStrategy = self::STRATEGY_SYMLINK; - $allowedStrategies = array(self::STRATEGY_SYMLINK); - } elseif (false === $transportOptions['symlink']) { - $currentStrategy = self::STRATEGY_MIRROR; - $allowedStrategies = array(self::STRATEGY_MIRROR); - } - - // Check we can use junctions safely if we are on Windows - if (Platform::isWindows() && self::STRATEGY_SYMLINK === $currentStrategy && !$this->safeJunctions()) { - $currentStrategy = self::STRATEGY_MIRROR; - $allowedStrategies = array(self::STRATEGY_MIRROR); - } + list($currentStrategy, $allowedStrategies) = $this->computeAllowedStrategies($transportOptions); $symfonyFilesystem = new SymfonyFilesystem(); $this->filesystem->removeDirectory($path); @@ -120,11 +99,13 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter } $isFallback = false; - if (self::STRATEGY_SYMLINK == $currentStrategy) { + if (self::STRATEGY_SYMLINK === $currentStrategy) { try { if (Platform::isWindows()) { // Implement symlinks as NTFS junctions on Windows - $this->io->writeError(sprintf('Junctioning from %s', $url), false); + if ($output) { + $this->io->writeError(sprintf('Junctioning from %s', $url), false); + } $this->filesystem->junction($realUrl, $path); } else { $absolutePath = $path; @@ -133,7 +114,9 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter } $shortestPath = $this->filesystem->findShortestPath($absolutePath, $realUrl); $path = rtrim($path, "/"); - $this->io->writeError(sprintf('Symlinking from %s', $url), false); + if ($output) { + $this->io->writeError(sprintf('Symlinking from %s', $url), false); + } if ($transportOptions['relative']) { $symfonyFilesystem->symlink($shortestPath, $path); } else { @@ -142,8 +125,10 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter } } catch (IOException $e) { if (in_array(self::STRATEGY_MIRROR, $allowedStrategies)) { - $this->io->writeError(''); - $this->io->writeError(' Symlink failed, fallback to use mirroring!'); + if ($output) { + $this->io->writeError(''); + $this->io->writeError(' Symlink failed, fallback to use mirroring!'); + } $currentStrategy = self::STRATEGY_MIRROR; $isFallback = true; } else { @@ -153,10 +138,12 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter } // Fallback if symlink failed or if symlink is not allowed for the package - if (self::STRATEGY_MIRROR == $currentStrategy) { + if (self::STRATEGY_MIRROR === $currentStrategy) { $realUrl = $this->filesystem->normalizePath($realUrl); - $this->io->writeError(sprintf('%sMirroring from %s', $isFallback ? ' ' : '', $url), false); + if ($output) { + $this->io->writeError(sprintf('%sMirroring from %s', $isFallback ? ' ' : '', $url), false); + } $iterator = new ArchivableFilesFinder($realUrl, array()); $symfonyFilesystem->mirror($realUrl, $path, $iterator); } @@ -225,7 +212,46 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter return ': Source already present'; } - return ''; + list($currentStrategy) = $this->computeAllowedStrategies($package->getTransportOptions()); + + if ($currentStrategy === self::STRATEGY_SYMLINK) { + if (Platform::isWindows()) { + return ': Junctioning from '.$package->getDistUrl(); + } + return ': Symlinking from '.$package->getDistUrl(); + } + + return ': Mirroring from '.$package->getDistUrl(); + } + + private function computeAllowedStrategies(array $transportOptions) + { + // When symlink transport option is null, both symlink and mirror are allowed + $currentStrategy = self::STRATEGY_SYMLINK; + $allowedStrategies = array(self::STRATEGY_SYMLINK, self::STRATEGY_MIRROR); + + $mirrorPathRepos = getenv('COMPOSER_MIRROR_PATH_REPOS'); + if ($mirrorPathRepos) { + $currentStrategy = self::STRATEGY_MIRROR; + } + + $symlinkOption = isset($transportOptions['symlink']) ? $transportOptions['symlink'] : null; + + if (true === $symlinkOption) { + $currentStrategy = self::STRATEGY_SYMLINK; + $allowedStrategies = array(self::STRATEGY_SYMLINK); + } elseif (false === $symlinkOption) { + $currentStrategy = self::STRATEGY_MIRROR; + $allowedStrategies = array(self::STRATEGY_MIRROR); + } + + // Check we can use junctions safely if we are on Windows + if (Platform::isWindows() && self::STRATEGY_SYMLINK === $currentStrategy && !$this->safeJunctions()) { + $currentStrategy = self::STRATEGY_MIRROR; + $allowedStrategies = array(self::STRATEGY_MIRROR); + } + + return array($currentStrategy, $allowedStrategies); } /**