When using drush make, it is sometimes desirable to use a link to the 'latest version' of a third-party library. In the case of Sourceforge, a double redirect is employed, first to the latest version of the software and then a second redirect to the nearest mirror location. Without the ability to follow redirects, it is necessary to give drush make a link to a specific version and mirror location, which defeats the ability of Sourceforge to distribute load.

As an example I try to download the getID3 library from Sourceforge using the following make file.

core = 7.x
api = 2

; Libraries
; Latest stable getID3 library
libraries[getid3][download][type] = "get"
libraries[getid3][download][url] = "http://sourceforge.net/projects/getid3/files/latest/download?source=files"
libraries[getid3][directory_name] = "getid3"
libraries[getid3][overwrite] = TRUE

The output from drush --debug follows:

/opt/drush/drush make --debug --no-core getid3.make.inc /tmp/testing
Bootstrap to phase 0. [0.03 sec, 2.2 MB]                             [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.03 sec, 2.34 MB] [bootstrap]
Cache HIT cid: 5.0-dev-commandfiles-0-d855919b3fd468a8cb48278c0b0162e2 [0.06 sec, 2.35 MB]                                                     [debug]
Bootstrap to phase 0. [0.14 sec, 5.16 MB]                                                                                                  [bootstrap]
Bootstrap to phase 0. [0.17 sec, 5.16 MB]                                                                                                  [bootstrap]
Found command: make (commandfile=make) [0.17 sec, 5.16 MB]                                                                                 [bootstrap]
Loading release_info engine. [0.21 sec, 5.18 MB]                                                                                              [notice]
Executing: which wget
  /usr/bin/wget
Executing: wget -q --timeout=30 -O /tmp/download_fileeOAW5D 'http://sourceforge.net/projects/getid3/files/latest/download?source=files'
Calling is_readable(/tmp/download_fileeOAW5D) [2.96 sec, 5.32 MB]                                                                              [debug]
Calling is_writable(/tmp/make_tmp_1330015110_4f466b865c60b) [2.96 sec, 5.32 MB]                                                                [debug]
Calling rename(/tmp/download_fileeOAW5D, /tmp/make_tmp_1330015110_4f466b865c60b/download) [2.96 sec, 5.32 MB]                                  [debug]
getid3 downloaded from http://sourceforge.net/projects/getid3/files/latest/download?source=files. [2.96 sec, 5.32 MB]                      [ok]
Executing: mv /tmp/make_tmp_1330015110_4f466b865c60b/download /tmp/make_tmp_1330015110_4f466b865c60b/__build__/sites/all/libraries/getid3
Executing: mv /tmp/make_tmp_1330015110_4f466b865c60b/__build__ /tmp/make_tmp_1330015110_4f466b865c60b/testing
Executing: cp -Rf /tmp/make_tmp_1330015110_4f466b865c60b/testing /tmp
Executing: rm -rf /tmp/make_tmp_1330015110_4f466b865c60b
Command dispatch complete [3.09 sec, 5.29 MB]                                                                                                 [notice]
Peak memory usage was 6.1 MB [3.09 sec, 5.29 MB]                                                                                              [memory]

# ls -l /tmp/testing/sites/all/libraries/getid3/
total 480K
drwxr-xr-x 2 root root 4.0K Feb 23 10:38 .
drwxr-xr-x 3 root root 4.0K Feb 23 10:38 ..
-rw------- 1 root root 470K Feb 23 10:38 download

As you can see, the getID3 library was actually downloaded, but since the filename was taken from the basename of the original URL, the type of file (.zip) was lost and so it was never unpacked.
The drush environment was:

# drush status
 PHP configuration     :  /etc/php5/cli/php.ini                                                                                              
 Drush version         :  5.0-dev                                                                                                            
 Drush configuration   :                                                                                                                     
 Drush alias files     :  /etc/drush/publisher.alias.drushrc.php /etc/drush/developer.alias.drushrc.php /etc/drush/drupal7.alias.drushrc.php 

A simple routine to get the filename and final URL from the headers when provided and default to the current behavior otherwise looks like this:

/**
 * drush_get_file_redirect()
 * Gets filename and final redirect from the headers for the given URL. 
 *
 * @param string $url
 * @return array ($filename, $url)
 */
function drush_get_file_redirect($url){
  $headers = get_headers($url, 1);
  if(!$headers) return false;                     //can't get headers
  if(array_key_exists('Content-Disposition', $headers)){
    preg_match('/^.*filename="(.*)"$/m', $headers['Content-Disposition'], $match);
    $filename = $match[1];
  }
  if(array_key_exists('Location', $headers)){
    $url = array_pop($headers['Location']);
  }
  if(!isset($filename)) $filename = basename($url);
  if($filename != basename($url)) return false;   //filename url mis-matched
  return array($filename, $url);
}

I'll attach a patch and the --debug results in the next comment.

Comments

dude4linux’s picture

StatusFileSize
new2.32 KB

With the attached patch installed, the --debug output is as follows:

# /opt/drush/drush make --debug --no-core getid3.make.inc /tmp/testing
Bootstrap to phase 0. [0.02 sec, 2.21 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.03 sec, 2.34 MB] [bootstrap]
Cache HIT cid: 5.0-dev-commandfiles-0-d855919b3fd468a8cb48278c0b0162e2 [0.05 sec, 2.35 MB]                                                     [debug]
Bootstrap to phase 0. [0.12 sec, 5.17 MB]                                                                                                  [bootstrap]
Bootstrap to phase 0. [0.14 sec, 5.17 MB]                                                                                                  [bootstrap]
Found command: make (commandfile=make) [0.14 sec, 5.17 MB]                                                                                 [bootstrap]
Loading release_info engine. [0.17 sec, 5.18 MB]                                                                                              [notice]
Executing: which wget
  /usr/bin/wget
Executing: wget -q --timeout=30 -O /tmp/download_filesePeuq 'http://voxel.dl.sourceforge.net/project/getid3/getID3%28%29%201.x/1.9.3/getid3-1.9.3-20111213.zip'
Calling is_readable(/tmp/download_filesePeuq) [2 sec, 5.32 MB]                                                                                 [debug]
Calling is_writable(/tmp/make_tmp_1330022918_4f468a06547ba) [2.01 sec, 5.33 MB]                                                                [debug]
Calling rename(/tmp/download_filesePeuq, /tmp/make_tmp_1330022918_4f468a06547ba/getid3-1.9.3-20111213.zip) [2.01 sec, 5.33 MB]                 [debug]
getid3 downloaded from http://sourceforge.net/projects/getid3/files/latest/download?source=files. [2.01 sec, 5.33 MB]                      [ok]
Executing: unzip /tmp/make_tmp_1330022918_4f468a06547ba/getid3-1.9.3-20111213.zip -d /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__
  Archive:  /tmp/make_tmp_1330022918_4f468a06547ba/getid3-1.9.3-20111213.zip
  getID3() v1.9.3-20111213
  James Heinrich
  info@getid3.org
  http://getid3.sourceforge.net
  http://www.getid3.org
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/license.txt
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/readme.txt
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/structure.txt
     creating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.audioinfo.class.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.basic.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.browse.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.cache.dbm.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.cache.mysql.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.joinmp3.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.mimeonly.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.mp3header.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.mysql.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.simple.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.simple.write.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.write.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/demo.zip.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/getid3.css
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/demos/index.php
     creating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/
     creating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/!delete any module you don't like, but check dependencies.txt/
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/extension.cache.dbm.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/extension.cache.mysql.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/getid3.lib.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/getid3.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.archive.gzip.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.archive.rar.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.archive.szip.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.archive.tar.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.archive.zip.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.asf.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.bink.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.flv.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.matroska.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.mpeg.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.nsv.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.quicktime.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.real.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.riff.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio-video.swf.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.aa.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.aac.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.ac3.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.au.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.avr.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.bonk.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.dss.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.dts.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.flac.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.la.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.lpac.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.midi.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.mod.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.monkey.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.mp3.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.mpc.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.ogg.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.optimfrog.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.rkau.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.shorten.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.tta.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.voc.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.vqf.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.audio.wavpack.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.bmp.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.efax.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.gif.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.jpg.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.pcd.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.png.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.svg.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.graphic.tiff.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.misc.cue.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.misc.exe.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.misc.iso.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.misc.msoffice.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.misc.par2.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.misc.pdf.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.tag.apetag.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.tag.id3v1.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.tag.id3v2.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.tag.lyrics3.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/module.tag.xmp.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.apetag.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.id3v1.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.id3v2.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.lyrics3.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.metaflac.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.real.php
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/getid3/write.vorbiscomment.php
     creating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/helperapps/
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/helperapps/readme.helperapps.txt
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/changelog.txt
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/dependencies.txt
    inflating: /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__/license.commercial.txt
Executing: ls /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__
  changelog.txt
  demos
  dependencies.txt
  getid3
  helperapps
  license.commercial.txt
  license.txt
  readme.txt
  structure.txt
Executing: rm -rf /tmp/make_tmp_1330022918_4f468a06547ba/__build__/sites/all/libraries/getid3
Executing: mv /tmp/make_tmp_1330022918_4f468a06547ba/__unzip__ /tmp/make_tmp_1330022918_4f468a06547ba/__build__/sites/all/libraries/getid3
Executing: rm /tmp/make_tmp_1330022918_4f468a06547ba/getid3-1.9.3-20111213.zip
Executing: mv /tmp/make_tmp_1330022918_4f468a06547ba/__build__ /tmp/make_tmp_1330022918_4f468a06547ba/testing
Executing: cp -Rf /tmp/make_tmp_1330022918_4f468a06547ba/testing /tmp
Executing: rm -rf /tmp/make_tmp_1330022918_4f468a06547ba
Command dispatch complete [2.34 sec, 5.3 MB]                                                                                                  [notice]
Peak memory usage was 6.11 MB [2.34 sec, 5.3 MB]                                                                                              [memory]

The attached patch changes two places where the filename is determined by using basename on the original URL. A complete solution would need to find all cases where the original URL is used. The best solution would be to call 'drush_get_file_redirect' and store both the URL and filename in the download array.

dude4linux’s picture

Opps. Patch #1 has a typo. Working on a fix.

steven jones’s picture

Component: Core Commands » Make
Status: Active » Closed (duplicate)

This should be fixed by #1447558: Make fails for library archives with no file "extension", please re-open this issue if its not.

dude4linux’s picture

Component: Make » Core Commands
Status: Closed (duplicate) » Active

Well, it wasn't fixed for me. I checked and the code from #1447558 is present in the version I tested above which still failed to unpack the zip file. I'm running:

# git show
commit 58034438c85f39977f11ca18670a79471308604e
Author: Moshe Weitzman <weitzman@tejasa.com>
Date:   Thu Feb 23 12:28:30 2012 -0500

which is failing unit tests and hangs when testing git.make

The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?  >> visitor cloned from git://git.drupal.org/project/visitor.git.                                                                                                            [ok]
 >> Checked out revision 5f256032cd4bcc2db45c962306d12c85131388ef.                                                                                                           [ok]
 >> tao cloned from git://git.drupal.org/project/tao.git.                                                                                                                    [ok]
 >> drupalbin cloned from git://git.drupal.org/project/drupalbin.git.                                                                                                        [ok]
 >> Checked out branch 5.x-1.x.                                                                                                                                              [ok]
 >> Checked out tag 6.x-3.2.                                                                                                                                                 [ok]

dude4linux’s picture

Status: Active » Fixed

Darn, your right. It is working now. I must have refreshed after running the last test before preparing my revised patch and didn't think to re-run the test. The unit tests are still hanging for me, but that might be a local config problem.

steven jones’s picture

Component: Core Commands » Make
Status: Fixed » Closed (duplicate)