[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/config/check/ -> PhabricatorSetupCheckPath.php (source)

   1  <?php
   2  
   3  final class PhabricatorSetupCheckPath extends PhabricatorSetupCheck {
   4  
   5    protected function executeChecks() {
   6      // NOTE: We've already appended `environment.append-paths`, so we don't
   7      // need to explicitly check for it.
   8      $path = getenv('PATH');
   9  
  10      if (!$path) {
  11        $summary = pht(
  12          'The environmental variable $PATH is empty. Phabricator will not '.
  13          'be able to execute some commands.');
  14  
  15        $message = pht(
  16          'The environmental variable $PATH is empty. Phabricator needs to '.
  17          'execute some system commands, like `svn`, `git`, `hg`, and `diff`. '.
  18          'To execute these commands, the binaries must be available in the '.
  19          'webserver\'s $PATH. You can set additional paths in Phabricator '.
  20          'configuration.');
  21  
  22        $this
  23          ->newIssue('config.environment.append-paths')
  24          ->setName(pht('$PATH Not Set'))
  25          ->setSummary($summary)
  26          ->setMessage($message)
  27          ->addPhabricatorConfig('environment.append-paths');
  28  
  29        // Bail on checks below.
  30        return;
  31      }
  32  
  33      // Users are remarkably industrious at misconfiguring software. Try to
  34      // catch mistaken configuration of PATH.
  35  
  36      $path_parts = explode(PATH_SEPARATOR, $path);
  37      $bad_paths = array();
  38      foreach ($path_parts as $path_part) {
  39        if (!strlen($path_part)) {
  40          continue;
  41        }
  42  
  43        $message = null;
  44        $not_exists = false;
  45        foreach (Filesystem::walkToRoot($path_part) as $part) {
  46          if (!Filesystem::pathExists($part)) {
  47            $not_exists = $part;
  48            // Walk up so we can tell if this is a readability issue or not.
  49            continue;
  50          } else if (!is_dir(Filesystem::resolvePath($part))) {
  51            $message = pht(
  52              "The PATH component '%s' (which resolves as the absolute path ".
  53              "'%s') is not usable because '%s' is not a directory.",
  54              $path_part,
  55              Filesystem::resolvePath($path_part),
  56              $part);
  57          } else if (!is_readable($part)) {
  58            $message = pht(
  59              "The PATH component '%s' (which resolves as the absolute path ".
  60              "'%s') is not usable because '%s' is not readable.",
  61              $path_part,
  62              Filesystem::resolvePath($path_part),
  63              $part);
  64          } else if ($not_exists) {
  65            $message = pht(
  66              "The PATH component '%s' (which resolves as the absolute path ".
  67              "'%s') is not usable because '%s' does not exist.",
  68              $path_part,
  69              Filesystem::resolvePath($path_part),
  70              $not_exists);
  71          } else {
  72            // Everything seems good.
  73            break;
  74          }
  75  
  76          if ($message !== null) {
  77            break;
  78          }
  79        }
  80  
  81        if ($message === null) {
  82          if (!phutil_is_windows() && !@file_exists($path_part.'/.')) {
  83            $message = pht(
  84              "The PATH component '%s' (which resolves as the absolute path ".
  85              "'%s') is not usable because it is not traversable (its '+x' ".
  86              "permission bit is not set).",
  87              $path_part,
  88              Filesystem::resolvePath($path_part));
  89          }
  90        }
  91  
  92        if ($message !== null) {
  93          $bad_paths[$path_part] = $message;
  94        }
  95      }
  96  
  97      if ($bad_paths) {
  98        foreach ($bad_paths as $path_part => $message) {
  99          $digest = substr(PhabricatorHash::digest($path_part), 0, 8);
 100  
 101          $this
 102            ->newIssue('config.PATH.'.$digest)
 103            ->setName(pht('$PATH Component Unusable'))
 104            ->setSummary(
 105              pht(
 106                'A component of the configured PATH can not be used by '.
 107                'the webserver: %s',
 108                $path_part))
 109            ->setMessage(
 110              pht(
 111                "The configured PATH includes a component which is not usable. ".
 112                "Phabricator will be unable to find or execute binaries located ".
 113                "here:".
 114                "\n\n".
 115                "%s".
 116                "\n\n".
 117                "The user that the webserver runs as must be able to read all ".
 118                "the directories in PATH in order to make use of them.",
 119                $message))
 120            ->addPhabricatorConfig('environment.append-paths');
 121        }
 122      }
 123  
 124    }
 125  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1