Closed (fixed)
Project:
Drush
Component:
PM (dl, en, up ...)
Priority:
Minor
Category:
Bug report
Assigned:
Reporter:
Created:
1 Dec 2009 at 22:50 UTC
Updated:
30 May 2011 at 01:31 UTC
Jump to comment: Most recent file
See issue #599698: Load a drushrc.php from cwd for an example use case where drush could not correctly find the drupal root when the user had set up some symlinks for convenience. The patch attached to this incident fixes the problem being experienced there in a more direct way, by following symlinks as they are encountered.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | findroot-ga-648280.patch | 1.18 KB | greg.1.anderson |
| #7 | locate-root-648280.patch | 1.79 KB | greg.1.anderson |
| #5 | 648280.patch | 1.74 KB | owen barton |
| #1 | drush-648280-1.patch | 639 bytes | malclocke |
| drush-HEAD-2009_12_01.patch | 980 bytes | greg.1.anderson |
Comments
Comment #1
malclocke commentedI had already uploaded a patch that fixes this with less impact at http://drupal.org/node/599698#comment-2131418 before that issue got hijacked and this one created, although the title of this issue is more descriptive of my problem. Re-attaching that patch here, have been using it for several weeks now without issue. It fixes the problem without the recursive walk in the patch above.
Comment #2
greg.1.anderson commentedI apologize; I fear I did not notice your patch above among all of the comments about loading drushrc.php from cwd (the title of the incident). Your solution is much more elegant than my patch; however, there are a number of people who call drush.php directly, and handling the symlinks in drush_locate_root solves this issue for them too. The recursive walk towards the directory root already exists in the current code; my patch might lengthen this walk by following symlinks.
@moshe: I leave it up to you which version you want to commit. There's no harm in taking both, but only one is necessary.
Comment #3
moshe weitzman commentedCommitted greg's patch since we do need to handle folks who call drush.php directly. I do that routinely:
Comment #5
owen barton commentedThis patch prevents Drush from finding a Drupal root on my sandbox. Here is the layout:
Drupal root is at /home/USER/workspace/drupal-6/
Site code is at /home/USER/workspace/sitename.6/
Site is symlinked in so /home/USER/workspace/drupal-6/sites/sitename.6 is a symlink to /home/USER/workspace/sitename.6/
I used to be able to cd to /home/USER/workspace/drupal-6/sites/sitename.6/ and Drush would walk up the current directory chain (not jumping to symlinks source destinations) and would find the drupal-6 directory. It would then correctly determine "sitename.6" as the active site, with no drushrc needed at all - I wrote this code specifically so it worked like this ;)
In other words this is the exact converse of the use case presented in #599698: Load a drushrc.php from cwd, which had the files stored inside the Drupal sites folder, and then a symlink out to the workspace. I think both are perfectly valid layouts, although I think mine is probably the more common, as it fits more naturally with Eclipse's workflow (and probably other project based editors) - the only way to replicate the other layout would be to create your project, close Eclipse, move the project, create a symlink back to where the project was and then restart Eclipse.
The only practical approach that comes to mind, (without adding restrictions or an obscure option) is simply to check using one approach (e.g. without link resolving) first and if nothing is found then check the other (e.g. with link resolving). The attached patch attempts this - I have tested with both layouts and it appears to work well, but a verification would be good.
The attached patch also fixes a separate issue I found with the original path in that it would break when relative symlinks are used, because readlink only returns the content of the link (e.g. "drupal-6/sites/sitename.6", or "../../sitename.6"), which are insufficient for Drupal roots. When I switched to using realpath it worked correctly however, because this always give a path from the filesystem root.
Comment #6
moshe weitzman commentedSeems reasonable to me. Lets give in the next couple of days soon so we can modify or commit this.
Comment #7
greg.1.anderson commentedI fixed two minor bugs, neither of which are necessary unless you accept that my somewhat odd use-case is valid. See below for the use case; first, the fixes:.
For my somewhat odd use case, consider a local drupal installation with two instances of drupal, 'mydrupal.com' and 'dev.mydrupal.com'. Because these are d6 sites, they both need to be stored at 'sites/mydrupal.com'. Therefore, we store them in separate drupal roots:
/srv/www/drupal-live/sites/mydrupal.com
/srv/www/drupal-dev/sites/mydrupal.com
The web server is set up so that 'mydrupal.com' serves files from /srv/www/drupal-live, and 'dev.mydrupal.com' serves files from /srv/www/drupal-dev. So far so good; now comes the odd part. For convenience, I also set up a symlink:
/srv/www/drupal-live/sites/dev.mydrupal.com -> /srv/www/drupal-dev/sites/mydrupal.com
This symlink is never used by drupal, it is only used by drush. It is sort of an odd duck; it would never be necessary in d7, and really wouldn't be necessary with a full compliment of site aliases set up, but I still have a number of these sitting around from the time before I had site aliases. The clincher is, I never identify my sites via cwd; I name them by dirname or alias name. Therefore, Owen's patch is good enough for my uses. I present these minor bug fixes because I feel they are technically more correct. I have tested both versions with Owen's layout and malclocke's layout, and both work fine in those cases. You may commit either version -- but if you take Owen's (with follow symlinks second), I think you should still at least take the 'break 2' bugfix.
Comment #8
greg.1.anderson commentedOkay, let's do this. I went ahead and committed #5. I didn't like keeping drush-HEAD broken against this common site layout configuration, and Owen's fix restores this important functionality.
Regarding #7, here is a new patch showing just the delta between #5 and #7. I've set the priority to minor; you can discuss and decide whether to take this modification or not at your leisure.
Comment #9
owen barton commentedThanks Greg!
The "break 2" certainly looks correct, and was just an oversight on my part.
The order of symlink/no-symlink search is not critical either way I think. It wasn't clear if the order affected your use case or not - if so, then it seems it would be fine to switch the order.
I doesn't really affect things, but the reasoning behind my suggestion - other than that I think it correlates to the more common layout - was that I think it maps to the users intention better, since they already chose to place themselves in the selected directory, rather than the "resolved" path, which they could have reached by doing "cd -P" rather than a straight "cd" if that was what they wanted.
Comment #10
moshe weitzman commentedseems like this is rtbc with or without owen's suggestion. i leave it to greg.
Comment #11
greg.1.anderson commentedComment #12
greg.1.anderson commentedSince the order of symlink / no-symlink doesn't affect Owen's use case, but does affect mine, I committed #8.
Comment #14
joachim commentedThis doesn't work with a symlink in my root folder like this:
lrwxr-xr-x 1 joachim staff 40 26 Sep 08:27 m-alpha -> sites/localhost.module-lab.alpha/modules
Comment #15
greg.1.anderson commentedDrush dl is behaving correctly in the above example. dl puts downloads at the cwd only if there is no bootstrapped site. In your example above, drush can find your site root at 'module-lab', so it puts your module at sites/all/modules where they belong. You have to use --destination if you want to force dl to put downloads in a site module folder.
Comment #16
joachim commentedIn that case, I don't understand that this issue fixed.
If I do
$ cd sites/localhost.module-lab.alpha/modules
$ drush dl kitten
then it correctly downloads to the subsite.
I thought the point of this issue was to correctly handle a symlink that points to a sites folder.
Comment #17
greg.1.anderson commentedOkay, I'll look at it again later.
Comment #18
greg.1.anderson commentedSee related comments in #1054068: Wrong resolution of @sites with symlinked sites directories
Comment #19
geek-merlin@greg: sorry, but evern after some thinking i don't understand your special use case in #7:
sorry id really don't understand - according to the docs you just create a 'dev.mydrupal.com' site - what am i missing?
(edit: this may go off-topic, feel free to pm me or ignore)
Comment #20
greg.1.anderson commentedIf you make a folder called "sites/dev.mydrupal.com", then certain edit actions will write "sites/dev.mydrupal.com" into the Drupal database. This means that your path will go awry (file not found) if you migrate dev.mydrupal.com back to mydrupal.com, where the path is expected to be "sites/mydrupal.com". One solution to this problem is to symlink sites/dev.mydrupal.com to sites/mydrupal.com on your live server, and let some of your paths in the database be "sites/mydrupal.com", and others be "sites/dev.mydrupal.com". On d6, I always make sure that the folder that contains settings.php has the same name for all of my dev / staging / test / live sites. Nowadays I just use "sites/default" and avoid multisites; it's simpler.
Comment #21
anarcat commentedI think the issue was reopened here for the wrong reason. The original bug report was about finding the drupal root - Drush now does that fine - the problem mentionned here is more like #1158510: drush dl sends everything to sites/all even though i'm in sites/example.com that I just opened (and have a patch for sitting in my branches).