From dbea8258711bcdcc3ddf620c7e2e9783ea19f00a Mon Sep 17 00:00:00 2001 From: William Sandin Date: Sun, 31 Dec 2017 19:35:09 +0700 Subject: [PATCH] Raise a warning if current user and owner of deploy dir doesn't match --- src/Composer/Command/SelfUpdateCommand.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 055f8af7f..1f86e7ed9 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -93,7 +93,9 @@ EOT $cacheDir = $config->get('cache-dir'); $rollbackDir = $config->get('data-dir'); $home = $config->get('home'); + $homeOwner = posix_getpwuid(fileowner($home)); $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; + $composeUser = posix_getpwuid(posix_geteuid()); if ($input->getOption('update-keys')) { return $this->fetchKeys($io, $config); @@ -107,6 +109,11 @@ EOT throw new FilesystemException('Composer update failed: the "'.$tmpDir.'" directory used to download the temp file could not be written'); } + // check if composer is running as the same user that owns the directory root + if ($composeUser !== $homeOwner) { + $io->writeError('You are running composer as "'.$composeUser.'", while "'.$home.'" is owned by "'.$homeOwner.'"'); + } + if ($input->getOption('rollback')) { return $this->rollback($output, $rollbackDir, $localFilename); }