diff --git a/drush_make.download.inc b/drush_make.download.inc index 2d6c070..55f8d9e 100644 --- a/drush_make.download.inc +++ b/drush_make.download.inc @@ -99,6 +99,19 @@ function _drush_make_download_file($download) { $download_path = $tmp_path . '/__download__'; drush_make_mkdir($download_path); + // Check if we have already downloaded a file+headers + $cache_path = sys_get_temp_dir() .'/__drushcache__/'. sha1($url); + $cache_file = $cache_path .'/file.contents'; + $cache_headers = $cache_path .'/file.headers'; + if ($download['request_type'] == 'get' && file_exists($cache_file) && file_exists($cache_headers)) { + drush_log(dt('Using cached download of @url', array('@url' => $url))); + $filename = $download_path . '/__destination__'; + copy($cache_file, $filename); + $headers = unserialize(file_get_contents($cache_headers)); + $success = TRUE; + $download_mechanism = 'cached'; // skip download methods below + } + if (!isset($download_mechanism) || $download_mechanism == 'curl') { $header_file = $tmp_path . '/__header__'; touch($header_file); @@ -183,6 +196,14 @@ function _drush_make_download_file($download) { if (!$success) { return; } + + // Save downloaded files in cache + if ($download_mechanism != 'cached') { + drush_make_mkdir($cache_path); + copy($filename, $cache_file); + file_put_contents($cache_headers, serialize($headers)); + } + // Much more useful in reverse order. $headers = array_reverse($headers); $content_type = '';