diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/download.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 0012cb18..d0f672f2 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
@@ -7,6 +7,8 @@ local util = require("luarocks.util") | |||
7 | local path = require("luarocks.path") | 7 | local path = require("luarocks.path") |
8 | local fetch = require("luarocks.fetch") | 8 | local fetch = require("luarocks.fetch") |
9 | local search = require("luarocks.search") | 9 | local search = require("luarocks.search") |
10 | local fs = require("luarocks.fs") | ||
11 | local dir = require("luarocks.dir") | ||
10 | 12 | ||
11 | help_summary = "Download a specific rock file from a rocks server." | 13 | help_summary = "Download a specific rock file from a rocks server." |
12 | help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" | 14 | help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" |
@@ -18,6 +20,20 @@ help = [[ | |||
18 | --arch=<arch> Download rock for a specific architecture. | 20 | --arch=<arch> Download rock for a specific architecture. |
19 | ]] | 21 | ]] |
20 | 22 | ||
23 | local function get_file(filename) | ||
24 | local protocol, pathname = dir.split_url(filename) | ||
25 | if protocol == "file" then | ||
26 | local ok, err = fs.copy(pathname, fs.current_dir()) | ||
27 | if ok then | ||
28 | return pathname | ||
29 | else | ||
30 | return nil, err | ||
31 | end | ||
32 | else | ||
33 | return fetch.fetch_url(filename) | ||
34 | end | ||
35 | end | ||
36 | |||
21 | function download(arch, name, version, all) | 37 | function download(arch, name, version, all) |
22 | local results, err | 38 | local results, err |
23 | local query = search.make_query(name, version) | 39 | local query = search.make_query(name, version) |
@@ -29,8 +45,7 @@ function download(arch, name, version, all) | |||
29 | results, err = search.find_suitable_rock(query) | 45 | results, err = search.find_suitable_rock(query) |
30 | end | 46 | end |
31 | if type(results) == "string" then | 47 | if type(results) == "string" then |
32 | local file = fetch.fetch_url(results) | 48 | return get_file(results) |
33 | return file | ||
34 | elseif type(results) == "table" and next(results) then | 49 | elseif type(results) == "table" and next(results) then |
35 | if all then | 50 | if all then |
36 | local all_ok = true | 51 | local all_ok = true |
@@ -39,7 +54,7 @@ function download(arch, name, version, all) | |||
39 | for version, versions in pairs(result) do | 54 | for version, versions in pairs(result) do |
40 | for _,items in pairs(versions) do | 55 | for _,items in pairs(versions) do |
41 | local filename = path.make_url(items.repo, name, version, items.arch) | 56 | local filename = path.make_url(items.repo, name, version, items.arch) |
42 | local ok, err = fetch.fetch_url(filename) | 57 | local ok, err = get_file(filename) |
43 | if not ok then | 58 | if not ok then |
44 | all_ok = false | 59 | all_ok = false |
45 | any_err = any_err .. "\n" .. err | 60 | any_err = any_err .. "\n" .. err |