function drush_sitealias_lookup_alias_by_path

8.0.x drush_sitealias_lookup_alias_by_path($path, $allow_best_match = FALSE)
6.x drush_sitealias_lookup_alias_by_path($path)
7.x drush_sitealias_lookup_alias_by_path($path)
master drush_sitealias_lookup_alias_by_path($path, $allow_best_match = FALSE)

Look for a defined alias that points to the specified site directory. The cache is tested first; if nothing is cached, then an exhaustive search is done for the specified site. If the exhaustive search returns a match, then it is cached.


$path: /path/to/drupal/sites/default

Return value

An alias record for the provided path

2 calls to drush_sitealias_lookup_alias_by_path()
drush_sitealias_get_record in includes/
Get a site alias record given an alias name or site specification.
drush_sitealias_site_set in commands/core/
Set the DRUPAL_SITE variable by writing it out to a temporary file that we then source for persistent site switching.


includes/, line 2211
The site alias API.


function drush_sitealias_lookup_alias_by_path($path, $allow_best_match = FALSE) {
  $result = drush_sitealias_quick_lookup_cached_alias_by_path($path);
  $fallback = array();
  if (empty($result)) {
    $aliases = _drush_sitealias_find_and_load_all_aliases();
    foreach ($aliases as $name => $alias_record) {
      if (!isset($alias_record['remote-host']) && isset($alias_record['root']) && isset($alias_record['uri']) && isset($alias_record['#name']) && isset($alias_record['#file'])) {
        if ($path == drush_sitealias_local_site_path($alias_record)) {
          $result = $alias_record;
        if (substr($path, 0, strlen($alias_record['root'])) == $alias_record['root']) {
          $fallback = $alias_record;
  if (empty($result) && $allow_best_match) {
    $result = $fallback;
  if (!empty($result)) {
  return $result;