diff options
| author | Fabio Mascarenhas <mascarenhas@lambda-2.local> | 2010-01-16 01:42:29 -0200 |
|---|---|---|
| committer | Fabio Mascarenhas <mascarenhas@lambda-2.local> | 2010-01-16 01:42:29 -0200 |
| commit | aadfebb888572534a566da6986a458db8c4c7250 (patch) | |
| tree | 6d2f5bf4c65e192e9a47ead4f2d719dde3295f63 /src | |
| parent | 3364429deccef52024ed5b0384d70d78dedd2fe7 (diff) | |
| download | luarocks-aadfebb888572534a566da6986a458db8c4c7250.tar.gz luarocks-aadfebb888572534a566da6986a458db8c4c7250.tar.bz2 luarocks-aadfebb888572534a566da6986a458db8c4c7250.zip | |
support for downloading with luasocket instead of luacurl
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs/lua.lua | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 220c046d..ad6d263b 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -8,10 +8,11 @@ local fs = require("luarocks.fs") | |||
| 8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
| 9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
| 10 | 10 | ||
| 11 | local socket_ok, http = pcall(require, "socket.http") | ||
| 11 | local zip_ok, lrzip = pcall(require, "luarocks.tools.zip") | 12 | local zip_ok, lrzip = pcall(require, "luarocks.tools.zip") |
| 12 | local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil | 13 | local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil |
| 13 | local lfs_ok, lfs = pcall(require, "lfs") | 14 | local lfs_ok, lfs = pcall(require, "lfs") |
| 14 | local curl_ok, curl = pcall(require, "luacurl") | 15 | --local curl_ok, curl = pcall(require, "luacurl") |
| 15 | local md5_ok, md5 = pcall(require, "md5") | 16 | local md5_ok, md5 = pcall(require, "md5") |
| 16 | local posix_ok, posix = pcall(require, "posix") | 17 | local posix_ok, posix = pcall(require, "posix") |
| 17 | 18 | ||
| @@ -484,6 +485,39 @@ end | |||
| 484 | end | 485 | end |
| 485 | 486 | ||
| 486 | --------------------------------------------------------------------- | 487 | --------------------------------------------------------------------- |
| 488 | -- LuaSocket functions | ||
| 489 | --------------------------------------------------------------------- | ||
| 490 | |||
| 491 | if socket_ok then | ||
| 492 | |||
| 493 | --- Download a remote file. | ||
| 494 | -- @param url string: URL to be fetched. | ||
| 495 | -- @param filename string or nil: this function attempts to detect the | ||
| 496 | -- resulting local filename of the remote file as the basename of the URL; | ||
| 497 | -- if that is not correct (due to a redirection, for example), the local | ||
| 498 | -- filename can be given explicitly as this second argument. | ||
| 499 | -- @return boolean: true on success, false on failure. | ||
| 500 | function download(url, filename) | ||
| 501 | assert(type(url) == "string") | ||
| 502 | assert(type(filename) == "string" or not filename) | ||
| 503 | |||
| 504 | filename = dir.path(fs.current_dir(), filename or dir.base_name(url)) | ||
| 505 | |||
| 506 | local res, status, headers, line = http.request(url) | ||
| 507 | if not res then return false, status end | ||
| 508 | if status ~= 200 then | ||
| 509 | return false, "Failed downloading: " .. line | ||
| 510 | end | ||
| 511 | local file = io.open(filename, "wb") | ||
| 512 | if not file then return false end | ||
| 513 | file:write(res) | ||
| 514 | file:close() | ||
| 515 | return true | ||
| 516 | end | ||
| 517 | |||
| 518 | end | ||
| 519 | |||
| 520 | --------------------------------------------------------------------- | ||
| 487 | -- MD5 functions | 521 | -- MD5 functions |
| 488 | --------------------------------------------------------------------- | 522 | --------------------------------------------------------------------- |
| 489 | 523 | ||
