From e37937d2f7f28d8bdf395ce1ad13df83d6b2b3ae Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 12 Dec 2013 23:24:54 -0200 Subject: Make the download command work with the file:// protocol --- src/luarocks/download.lua | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') 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") local path = require("luarocks.path") local fetch = require("luarocks.fetch") local search = require("luarocks.search") +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") help_summary = "Download a specific rock file from a rocks server." help_arguments = "[--all] [--arch= | --source | --rockspec] [ []]" @@ -18,6 +20,20 @@ help = [[ --arch= Download rock for a specific architecture. ]] +local function get_file(filename) + local protocol, pathname = dir.split_url(filename) + if protocol == "file" then + local ok, err = fs.copy(pathname, fs.current_dir()) + if ok then + return pathname + else + return nil, err + end + else + return fetch.fetch_url(filename) + end +end + function download(arch, name, version, all) local results, err local query = search.make_query(name, version) @@ -29,8 +45,7 @@ function download(arch, name, version, all) results, err = search.find_suitable_rock(query) end if type(results) == "string" then - local file = fetch.fetch_url(results) - return file + return get_file(results) elseif type(results) == "table" and next(results) then if all then local all_ok = true @@ -39,7 +54,7 @@ function download(arch, name, version, all) for version, versions in pairs(result) do for _,items in pairs(versions) do local filename = path.make_url(items.repo, name, version, items.arch) - local ok, err = fetch.fetch_url(filename) + local ok, err = get_file(filename) if not ok then all_ok = false any_err = any_err .. "\n" .. err -- cgit v1.2.3-55-g6feb