1
0
Fork 0

* added execute() wrapper to generalize command execution in downloader

* added Composer\Util\Svn::doAuthDance() to ask for credentials in interactive sessions
pull/410/head
till 2012-03-22 18:41:10 +01:00
parent 059bde1adb
commit c7dc49fe10
1 changed files with 50 additions and 2 deletions

View File

@ -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.
*