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.

4 calls to drush_locate_root()
drush_complete_cache_cid in includes/complete.inc
Generate a cache id.
drush_sitealias_build_record_from_settings_file in includes/sitealias.inc
_drush_bootstrap_select_drupal_site in includes/bootstrap.inc
Determine which Drupal site will be selected.
_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.

File

includes/environment.inc, line 342
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;
}