diff --git a/includes/environment.inc b/includes/environment.inc index b0cb3cd358528f7b833ee5033b8bd5df41d6d300..cc8b385aa2beaa4187f6ed37b6bfd7e2b4006fea 100644 --- a/includes/environment.inc +++ b/includes/environment.inc @@ -382,11 +382,16 @@ function drush_locate_root($start_path = NULL) { */ function drush_valid_drupal_root($path) { if (!empty($path) && is_dir($path)) { - $candidates = array('includes/common.inc', 'core/includes/common.inc'); - foreach ($candidates as $candidate) { - if (file_exists($path . '/' . $candidate)) { - return $candidate; - } + // Drupal 8 root. + $candidate = 'core/includes/common.inc'; + if (file_exists($path . '/' . $candidate)) { + return $candidate; + } + // Drupal 7 root. Ensure $path is not inside core/ of a Drupal 8 root. + // Double check: parent is core/ and ../sites/example.sites.php exists. + $candidate = 'includes/common.inc'; + if (file_exists($path . '/' . $candidate) && ((basename($path) != 'core') && !file_exists($path . '../sites/example.sites.php'))) { + return $candidate; } } return FALSE;