diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index 5a47a755d..5d5929c7c 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -21,6 +21,11 @@ use Composer\Util\Svn as SvnUtil; */ class SvnDownloader extends VcsDownloader { + /** + * @var bool $useAuth + */ + protected $useAuth = false; + /** * @var \Composer\Util\Svn $util */ @@ -39,7 +44,7 @@ class SvnDownloader extends VcsDownloader $command = $util->getCommand("svn co", sprintf("%s/%s", $url, $ref), $path); $this->io->write(" Checking out ".$package->getSourceReference()); - $this->process->execute($command); + $this->execute($command, $util); } /** @@ -54,7 +59,7 @@ class SvnDownloader extends VcsDownloader $command = $util->getCommand("svn switch", sprintf("%s/%s", $url, $ref)); $this->io->write(" Checking out " . $ref); - $this->process->execute(sprintf('cd %s && %s', $path, $command)); + $this->execute(sprintf('cd %s && %s', $path, $command), $util); } /** @@ -68,6 +73,49 @@ class SvnDownloader extends VcsDownloader } } + /** + * Wrap {@link \Composer\Util\ProcessExecutor::execute(). + * + * @param string $cmd + * @param SvnUtil $util + * + * @return string + */ + protected function execute($command, SvnUtil $util) + { + $status = $this->process->execute($command, $output); + if ($status == 0) { + return $output; + } + + // this could be any failure, since SVN exits with 1 always + + if (empty($output)) { + $output = $this->process->getErrorOutput(); + } + + if (!$this->io->isInteractive()) { + return $output; + } + + // the error is not auth-related + if (strpos($output, 'authorization failed:') === false) { + return $output; + } + + // no authorization has been detected so far + if (!$this->useAuth) { + $this->useAuth = $util->doAuthDance()->hasAuth(); + $credentials = $util->getCredentialString(); + + // restart the process + $output = $this->execute($command . ' ' . $credentials, $util); + } else { + $this->io->write("Authorization failed: {$command}"); + } + return $output; + } + /** * This is heavy - recreating Util often. *