浏览代码

Adding check to confirm POSIX is defined and callable

William Sandin 7 年之前
父节点
当前提交
4296fe657f
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      src/Composer/Command/SelfUpdateCommand.php

+ 7 - 5
src/Composer/Command/SelfUpdateCommand.php

@@ -93,9 +93,7 @@ EOT
         $cacheDir = $config->get('cache-dir');
         $cacheDir = $config->get('cache-dir');
         $rollbackDir = $config->get('data-dir');
         $rollbackDir = $config->get('data-dir');
         $home = $config->get('home');
         $home = $config->get('home');
-        $homeOwner = posix_getpwuid(fileowner($home));
         $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
         $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
-        $composeUser = posix_getpwuid(posix_geteuid());
 
 
         if ($input->getOption('update-keys')) {
         if ($input->getOption('update-keys')) {
             return $this->fetchKeys($io, $config);
             return $this->fetchKeys($io, $config);
@@ -109,9 +107,13 @@ EOT
             throw new FilesystemException('Composer update failed: the "'.$tmpDir.'" directory used to download the temp file could not be written');
             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('<warning>You are running composer as "'.$composeUser.'", while "'.$home.'" is owned by "'.$homeOwner.'"</warning>');
+        // 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('<warning>You are running composer as "'.$composeUser.'", while "'.$home.'" is owned by "'.$homeOwner.'"</warning>');
+            }
         }
         }
 
 
         if ($input->getOption('rollback')) {
         if ($input->getOption('rollback')) {