1
0
Fork 0

Added earlier permission checks in local filesystem before start download.

pull/1886/head
Phansys 2013-05-10 22:39:31 -03:00
parent d574e5fcab
commit b992c29eb5
1 changed files with 14 additions and 3 deletions

View File

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Composer;
use Composer\Util\RemoteFilesystem;
use Composer\Downloader\FilesystemException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -41,6 +42,18 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
$tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar').'-temp.phar';
// check for permissions in local filesystem before start connection process
if (!is_writable($tempDirectory = dirname($tempFilename))) {
throw new FilesystemException('Composer update failed: the "'.$tempDirectory.'" directory used to download the temp file could not be written');
}
if (!is_writable($localFilename)) {
throw new FilesystemException('Composer update failed: the "'.$localFilename. '" file could not be written');
}
$protocol = extension_loaded('openssl') ? 'https' : 'http';
$rfs = new RemoteFilesystem($this->getIO());
$latest = trim($rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/version', false));
@ -48,9 +61,7 @@ EOT
if (Composer::VERSION !== $latest) {
$output->writeln(sprintf("Updating to version <info>%s</info>.", $latest));
$remoteFilename = $protocol . '://getcomposer.org/composer.phar';
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
$tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar').'-temp.phar';
$remoteFilename = $protocol . '://getcomposer.org/composer.phar';
$rfs->copy('getcomposer.org', $remoteFilename, $tempFilename);