function drush_locate_root

8.0.x environment.inc drush_locate_root($start_path = NULL)
6.x environment.inc drush_locate_root($start_path = NULL)
7.x environment.inc drush_locate_root($start_path = NULL)
3.x environment.inc drush_locate_root($start_path = NULL)
4.x environment.inc drush_locate_root($start_path = NULL)
5.x environment.inc drush_locate_root($start_path = NULL)
master environment.inc drush_locate_root($start_path = NULL)

Exhaustive depth-first search to try and locate the Drupal root directory. This makes it possible to run drush from a subdirectory of the drupal root.

Parameters

Search start path. Defaults to current working directory.:

Return value

A path to drupal root, or FALSE if not found.

6 calls to drush_locate_root()
drush_sitealias_build_record_from_settings_file in includes/sitealias.inc
drush_site_path in includes/environment.inc
Like Drupal conf_path, but searching from beneath. Allows proper site uri detection in site sub-directories.
_drush_bootstrap_drupal_root_validate in includes/environment.inc
Validate the DRUSH_BOOTSTRAP_DRUPAL_ROOT phase.
_drush_find_local_sites_in_sites_folder in includes/sitealias.inc
Return a list of all of the local sites at the specified 'sites' folder.
_drush_sitealias_find_and_load_alias in includes/sitealias.inc
Worker function called by _drush_sitealias_load_alias and drush_sitealias_load_all. Traverses the alias search path and finds the specified alias record.

... See full list

File

includes/environment.inc, line 887
Functions used by drush to query the environment and setting the current configuration.

Code

function drush_locate_root($start_path = NULL) {
  $drupal_root = FALSE;

  $start_path = empty($start_path) ? drush_cwd() : $start_path;
  foreach (array(TRUE, FALSE) as $follow_symlinks) {
    $path = $start_path;
    if ($follow_symlinks && is_link($path)) {
      $path = realpath($path);
    }
    // Check the start path.
    if (drush_valid_drupal_root($path)) {
      $drupal_root = $path;
      break;
    }
    else {
      // Move up dir by dir and check each.
      while ($path = _drush_shift_path_up($path)) {
        if ($follow_symlinks && is_link($path)) {
          $path = realpath($path);
        }
        if (drush_valid_drupal_root($path)) {
          $drupal_root = $path;
          break 2;
        }
      }
    }
  }

  return $drupal_root;
}