diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 055f8af7f..3ed72bdbc 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -107,6 +107,15 @@ 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, only if POSIX is defined and callable + if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) { + $composeUser = posix_getpwuid(posix_geteuid()); + $homeOwner = posix_getpwuid(fileowner($home)); + 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); }