Closed (fixed)
Project:
Drush
Version:
8.x-6.x-dev
Component:
Base system (internal API)
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Dec 2012 at 10:02 UTC
Updated:
14 Jun 2013 at 20:30 UTC
Jump to comment: Most recent file
Comments
Comment #1
hansfn commentedComment #2
hansfn commentedTabs replaced with spaces ;-)
Comment #3
hansfn commentedRemoved a typo - drupal7 and drupal8 key mixed up in last return statement.
Comment #4
moshe weitzman commentedCode still looks confused about version. Maybe it is deliberate but it looks weird at quick lance. See these two adjacent lines:
Comment #5
hansfn commentedThx for taking a look. The code isn't confused at all. Maybe an example will explain what I'm trying to handle:
You are located inside /docroot/drupal8/core (or any subdirectory) when running drush. From that location, the Drupal 7 path candidate "includes/common.inc" will match. Without an extra check to see if we are inside a D8 core directory, Drush will accept this as the Drupal root and we get "/docroot/drupal8/core" as root in stead of the correct "/docroot/drupal8".
The patch fixes this problem, without breaking the existing behavior. Maybe my comment could be clearer - it was the best I could come up with. Accept for this, I don't see that the patch needs more work ;-)
Comment #6
jonhattanProposed resolution
Comment #7
hansfn commentedThe patch above is functionally equivalent to mine. I guess the "../sites/sites.php" extra check is to catch the case when someone installs Drupal 7 in a folder named "core"?
Some issues:
1) The comment says "core/sites/sites.php" which doesn't exist AFAIK.
2) In a "standard" installation "../sites/sites.php" also doesn't exist so checking for it doesn't add any value. Maybe check for "../sites/example.sites.php" (or "../sites/default") instead.
Updated patch attached.
Comment #8
jonhattanYou're right. Committed #7
Comment #9
hansfn commentedHm, I just tested and there is a tiny bug in our patch - a missing slash. See attached patch.
Another minor thing: In the D7 case we added an extra check in case a user installed D7 inside a directory named "core". If we want to be really pedantic (and consistent), I guess we should add the same check in the D8 case: If we are running drush from the parent directory of a D7 installation in a directory named "core", the current code will return wrong Drupal root since the D8 candidate matches.
Comment #10
hansfn commentedHm, maybe I should have set the status to active ;-)
Comment #11
tim.plunkettWorks for me, thanks!
Comment #12
tim.plunkettI missed #8, I was RTBCing a committed patch :)
Comment #13
hansfn commentedIt seems my trivial bug fix in comment #9 has been committed (by moshe weitzman on the 29th of January). Apparently your RTBC had some effect ;-)
Comment #14
jonhattanI had a more accurate patch locally to check for the presence of composer.json. Committed: http://drupalcode.org/project/drush.git/commit/a6fedd1
Comment #15
hansfn commentedNice, jonhattan. There is one minor issue with your patch - your replace and with or in the "Drupal 7 root" case. This means that a user installing Drupal 7 in a directory named "core" is in trouble ... I have attached a trivial fix.
Comment #16
jonhattan@hansfn #14 works for me. Did you test it?
(file_exists($path . '/' . $candidate) && ((basename($path) != 'core') || !file_exists($path . '/../core/composer.json')))As I read it: candidate exists AND basename is not core OR (because basename is core)
core/composer.jsondoesn't exist.Comment #17
hansfn commentedSorry, jonhattan, your code works - I was wrong. I misunderstood the logic.
PS! If basename($path) is 'core', you might use
!file_exists($path . '/composer.json')in stead of
!file_exists($path . '/../core/composer.json')Comment #19
BMDan commentedcomposer.json is no longer in the root of core, so being anywhere under "core" results in misidentification of "core/" as a D7 root.
Full list of "composer.json"s under the real docroot:
Based on this, it looks like the test should be ../composer.json instead of ../core/composer.json, but I'm hesitant to actually suggest that without understanding the full logic.
Comment #20
BMDan commentedComment #21
hansfn commentedThat is the correct fix AFAICT too. The logic is simple - there is no composer.json in D7 (or D6) so the existence of such a file indicates very strongly that this is D8 ;-)
Comment #22
moshe weitzman commentedCommitted as suggested. Thanks BMDan and hansfn