aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-16 17:58:37 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-16 17:58:37 +0300
commitb9b598374a73d77fb456bb087df993e3754252b5 (patch)
treeeec7b6f778f31661500a2e6edb8b27e2204875c5
parent228a07b1531a090a6d4421f07bd9593946b07c2e (diff)
downloadluarocks-b9b598374a73d77fb456bb087df993e3754252b5.tar.gz
luarocks-b9b598374a73d77fb456bb087df993e3754252b5.tar.bz2
luarocks-b9b598374a73d77fb456bb087df993e3754252b5.zip
download
-rw-r--r--src/luarocks/download-original.lua68
-rw-r--r--src/luarocks/download.lua70
2 files changed, 107 insertions, 31 deletions
diff --git a/src/luarocks/download-original.lua b/src/luarocks/download-original.lua
new file mode 100644
index 00000000..07a2a65f
--- /dev/null
+++ b/src/luarocks/download-original.lua
@@ -0,0 +1,68 @@
1local download = {}
2
3local path = require("luarocks.path")
4local fetch = require("luarocks.fetch")
5local search = require("luarocks.search")
6local queries = require("luarocks.queries")
7local fs = require("luarocks.fs")
8local dir = require("luarocks.dir")
9local util = require("luarocks.util")
10
11local function get_file(filename)
12 local protocol, pathname = dir.split_url(filename)
13 if protocol == "file" then
14 local ok, err = fs.copy(pathname, fs.current_dir(), "read")
15 if ok then
16 return pathname
17 else
18 return nil, err
19 end
20 else
21 -- discard third result
22 local ok, err = fetch.fetch_url(filename)
23 return ok, err
24 end
25end
26
27function download.download(arch, name, namespace, version, all, check_lua_versions)
28 local substring = (all and name == "")
29 local query = queries.new(name, namespace, version, substring, arch)
30 local search_err
31
32 if all then
33 local results = search.search_repos(query)
34 local has_result = false
35 local all_ok = true
36 local any_err = ""
37 for name, result in pairs(results) do -- luacheck: ignore 422
38 for version, items in pairs(result) do -- luacheck: ignore 422
39 for _, item in ipairs(items) do
40 -- Ignore provided rocks.
41 if item.arch ~= "installed" then
42 has_result = true
43 local filename = path.make_url(item.repo, name, version, item.arch)
44 local ok, err = get_file(filename)
45 if not ok then
46 all_ok = false
47 any_err = any_err .. "\n" .. err
48 end
49 end
50 end
51 end
52 end
53
54 if has_result then
55 return all_ok, any_err
56 end
57 else
58 local url
59 url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions)
60 if url then
61 return get_file(url)
62 end
63 end
64 local rock = util.format_rock_name(name, namespace, version)
65 return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".")
66end
67
68return download
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index 07a2a65f..068ade96 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -1,4 +1,5 @@
1local download = {} 1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local download = {}
2
2 3
3local path = require("luarocks.path") 4local path = require("luarocks.path")
4local fetch = require("luarocks.fetch") 5local fetch = require("luarocks.fetch")
@@ -18,51 +19,58 @@ local function get_file(filename)
18 return nil, err 19 return nil, err
19 end 20 end
20 else 21 else
21 -- discard third result 22
22 local ok, err = fetch.fetch_url(filename) 23 local ok, err = fetch.fetch_url(filename)
23 return ok, err 24 return ok, err
24 end 25 end
25end 26end
26 27
27function download.download(arch, name, namespace, version, all, check_lua_versions) 28function download.download_all(arch, name, namespace, version)
28 local substring = (all and name == "") 29 local substring = (name == "")
29 local query = queries.new(name, namespace, version, substring, arch) 30 local query = queries.new(name, namespace, version, substring, arch)
30 local search_err 31 local search_err
31 32
32 if all then 33 local results = search.search_repos(query)
33 local results = search.search_repos(query) 34 local has_result = false
34 local has_result = false 35 local all_ok = true
35 local all_ok = true 36 local any_err = ""
36 local any_err = "" 37 for name, result in pairs(results) do
37 for name, result in pairs(results) do -- luacheck: ignore 422 38 for version, items in pairs(result) do
38 for version, items in pairs(result) do -- luacheck: ignore 422 39 for _, item in ipairs(items) do
39 for _, item in ipairs(items) do 40
40 -- Ignore provided rocks. 41 if item.arch ~= "installed" then
41 if item.arch ~= "installed" then 42 has_result = true
42 has_result = true 43 local filename = path.make_url(item.repo, name, version, item.arch)
43 local filename = path.make_url(item.repo, name, version, item.arch) 44 local ok, err = get_file(filename)
44 local ok, err = get_file(filename) 45 if not ok then
45 if not ok then 46 all_ok = false
46 all_ok = false 47 any_err = any_err .. "\n" .. err
47 any_err = any_err .. "\n" .. err
48 end
49 end 48 end
50 end 49 end
51 end 50 end
52 end 51 end
52 end
53 53
54 if has_result then 54 if has_result then
55 return all_ok, any_err 55 return all_ok, any_err
56 end
57 else
58 local url
59 url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions)
60 if url then
61 return get_file(url)
62 end
63 end 56 end
57
58 local rock = util.format_rock_name(name, namespace, version)
59 return nil, "Could not find a result named " .. rock .. (search_err and ": " .. search_err or ".")
60end
61
62function download.download_file(arch, name, namespace, version, check_lua_versions)
63 local query = queries.new(name, namespace, version, false, arch)
64 local search_err
65
66 local url
67 url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions)
68 if url then
69 return get_file(url)
70 end
71
64 local rock = util.format_rock_name(name, namespace, version) 72 local rock = util.format_rock_name(name, namespace, version)
65 return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") 73 return nil, "Could not find a result named " .. rock .. (search_err and ": " .. search_err or ".")
66end 74end
67 75
68return download 76return download