From 95a9ac880b88e4a25cf7b323d885734ed26a4b8a Mon Sep 17 00:00:00 2001 From: Dimitrios Kanellopoulos Date: Sat, 16 Nov 2013 18:52:44 +0100 Subject: [PATCH] Check if current dir is writable and if not try the cache dir from settings --- src/Composer/Command/SelfUpdateCommand.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 86ecf1a8a..e8c373197 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -47,11 +47,14 @@ EOT $cacheDir = $config->get('cache-dir'); $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; - $tempFilename = $cacheDir . basename($localFilename, '.phar').'-temp.phar'; + + // Check if current dir is writable and if not try the cache dir from settings + $tmpDir = is_writable(dirname($localFilename))? dirname($localFilename) . '/' : $cacheDir; + $tempFilename = $tmpDir . 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($tmpDir)) { + throw new FilesystemException('Composer update failed: the "'.$tmpDir.'" directory used to download the temp file could not be written'); } if (!is_writable($localFilename)) {