From d574e5fcab8116f397158808780f8505aa8faaad Mon Sep 17 00:00:00 2001 From: Phansys Date: Fri, 10 May 2013 22:37:30 -0300 Subject: [PATCH 1/2] Added FilesystemException to handle errors on local filesystem. --- .../Downloader/FilesystemException.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/Composer/Downloader/FilesystemException.php diff --git a/src/Composer/Downloader/FilesystemException.php b/src/Composer/Downloader/FilesystemException.php new file mode 100644 index 000000000..9829b7d4a --- /dev/null +++ b/src/Composer/Downloader/FilesystemException.php @@ -0,0 +1,26 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Downloader; + +/** + * Exception thrown when issues exist on local filesystem + * + * @author Javier Spagnoletti + */ +class FilesystemException extends \Exception +{ + public function __construct($message = null, $code = null, \Exception $previous = null) + { + parent::__construct("Filesystem exception: \n".$message, $code, $previous); + } +} From b992c29eb5ce106b9746d7e606e967f738f0058f Mon Sep 17 00:00:00 2001 From: Phansys Date: Fri, 10 May 2013 22:39:31 -0300 Subject: [PATCH 2/2] Added earlier permission checks in local filesystem before start download. --- src/Composer/Command/SelfUpdateCommand.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 82f11af92..5358af43a 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -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 %s.", $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);