If a user doesn't have permission to write to the main Drupal directory, then pm-download fails. This happens even when --destination or --use-site-dir are used.
This is occurring because function package_handler_download_project in pm/package_handler/wget.inc is using the current working directory for the wget and curl calls, even though drush_pm_download in commands/pm/pm.drush.inc specifies that it should use a temporary directory.
This was a hard issue to diagnose because all of the debug output claims the temporary directory is being used, but the actual wget and curl calls ignore it.
Instead of changing all the wget, curl, and validation calls, my proposed fix just changes the current working directory at the start of package_handler_download, and then restores it to the previous value at the end of the function.
Issue #1168812: Respect filesystem permissions suggests that a temporary directory shouldn't be used, or at least that the temporary directory should live under the sites directory. This patch should not interfere with any of those approaches, so long as they set $request['base_project_path'] appropriately before the call to package_handler_download.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | drush-1272820.patch | 1.88 KB | jonhattan |
| #8 | pm_download_use_tmp_dir-1272820-8.patch | 1.43 KB | resplin |
| #1 | pm_download_use_tmp_dir-1272820-1.patch | 842 bytes | resplin |
Comments
Comment #1
resplin commentedPatch attached.
Comment #2
resplin commentedI forgot to mention that I verified the bug exists in version 4.5 and version 4.6-dev checked out from master.
The patch applies cleanly to both versions and solves the problem in both versions.
Comment #3
greg.1.anderson commentedSee also #1168812: Respect filesystem permissions. It's one or the other...
Comment #4
resplin commentedAs I mentioned in the body of the issue, I don't think it is one or the other.
The current functionality is broken in that what happens is not what the code comments and debug messages say should happen. This patch brings behavior in line with the expectations within the code.
Should #1168812 be implemented, this patch will still be necessary.
Comment #5
greg.1.anderson commentedMissed the last paragraph of #0. Here's a better title; please correct if I got it wrong.
Comment #6
steinmb commentedAlso got confused this where, drush wrongly claim to be downloading to temp. Dunno what's the best solution, dl to temp, or dl to root (currently in 4.5), but at least should the --debug info. from drush be correct.
Comment #7
resplin commentedgreg.1.anderson: Thank you for the improved title.
steinmb: Downloading to Drupal root doesn't work for environments that don't have permission there. It needs to honor the --use-site-dir flag.
Comment #8
resplin commentedI found another instance of the same problem when wget and curl are called in includes/drush.inc in order to download the release history. The 7.x-4.5 release tries to use the Drupal directory by default, which often doesn't have write permission in a multi-site install. When applied to the 7.x-4.5 tarball, the attached patch allows downloads to succeed by fixing both the permission problem in includes/drush.inc, but also in commands/pm/package_handler/wget.inc (it includes my previous patch).
However, this patch does not apply cleanly against the current 7.x-4.x branch (reports as 4.6-dev). _drush_download_file was refactored, but appears to suffer from the same permissions problem. In that branch, commands/pm/package_handle/wget.inc definitely needs to be patched to work. But something else is also getting hung up when the Drupal directory is not writeable.
Comment #9
greg.1.anderson commentedThis patch is only for the 4.x branch; in master,
_drush_download_fileis downloading to the locationdrush_tempnam('download_file')stipulates; it is then moved to $destination, which is 'base_project_path'.If we're going to fix this in 4.x, seems like we should backport the code that exists in master rather than doing it some other way. In any event, the submitted patch should be against the
7.x-4.xbranch.Comment #10
jonhattan#8 was fixed in #1273342: Download release history to tmp instead of drupal root.
Let me analyze the OP issue. I'm all for downloading to tmp folder always.
Comment #11
jonhattanIt is not an issue in drush 5.x, that uses drush_download_file() --that was buggy and fixed in #1273342
In 4.x it is a regression introduced in http://drupalcode.org/project/drush.git/commitdiff/2f28b7f244225a1db5306...
Comment #12
jonhattanAttached patch fixes the regression (untested). The other option is to leverage drush_download_file().
It is Mark's decision what way to go.
Comment #13
anarcat commentedthis works. I can commit it if marks doesn't veto it. this is a significant regression in Aegir environments.
Comment #14
greg.1.anderson commentedI agree that it would be a good thing for this to go into 4.x.
Comment #15
msonnabaum commentedI'm fine with this.
Comment #16
anarcat commentedpatch pushed after double-checking with mark on irc
Comment #17
anarcat commentedHold the 4.x release presses! :) This creates *another* regression:
weird...
I have reverted the previous patch, back to the drawing board - all of a sudden, backporting drush_download_file seems interesting again.
Comment #18
msonnabaum commentedThe drush_download_file() backport is certainly my preference, but since we're so close to the drush 5 release, I'm ok with anything that doesn't create a regression.
Comment #19
greg.1.anderson commentedSorry I didn't have time to work on this today (and therefore won't be getting to it). I did take a look at it, though, and noticed that drush_download_file has already been ported to Drush 4; it's right there in includes/drush.inc. The code in wget.inc is similar enough that it should be relatively straightforward to move the code from Drush 5 over to Drush 4. Or so it appears.
Comment #20
greg.1.anderson commentedThis issue was marked
closed (won't fix)because Drush has moved to Github.If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to
closed (duplicate).Please ask support questions on Drupal Answers.