diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:48:59 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | 8f656b5a26c6c5352589e8ed294a8c27871b65a7 (patch) | |
tree | 3155f025f97741dfa69911d9fe503df4226ecca2 /src | |
parent | df302d44df3851a79ca8e5b4cd088ef2e1d8fb62 (diff) | |
download | luarocks-8f656b5a26c6c5352589e8ed294a8c27871b65a7.tar.gz luarocks-8f656b5a26c6c5352589e8ed294a8c27871b65a7.tar.bz2 luarocks-8f656b5a26c6c5352589e8ed294a8c27871b65a7.zip |
Teal: convert luarocks.download
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/download.tl | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/src/luarocks/download.tl b/src/luarocks/download.tl index 07a2a65f..f993da0f 100644 --- a/src/luarocks/download.tl +++ b/src/luarocks/download.tl | |||
@@ -1,4 +1,5 @@ | |||
1 | local download = {} | 1 | local record download |
2 | end | ||
2 | 3 | ||
3 | local path = require("luarocks.path") | 4 | local path = require("luarocks.path") |
4 | local fetch = require("luarocks.fetch") | 5 | local fetch = require("luarocks.fetch") |
@@ -8,7 +9,7 @@ local fs = require("luarocks.fs") | |||
8 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
9 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
10 | 11 | ||
11 | local function get_file(filename) | 12 | local function get_file(filename: string): string, string |
12 | local protocol, pathname = dir.split_url(filename) | 13 | local protocol, pathname = dir.split_url(filename) |
13 | if protocol == "file" then | 14 | if protocol == "file" then |
14 | local ok, err = fs.copy(pathname, fs.current_dir(), "read") | 15 | local ok, err = fs.copy(pathname, fs.current_dir(), "read") |
@@ -24,43 +25,50 @@ local function get_file(filename) | |||
24 | end | 25 | end |
25 | end | 26 | end |
26 | 27 | ||
27 | function download.download(arch, name, namespace, version, all, check_lua_versions) | 28 | function download.download_all(arch: string, name: string, namespace: string, version: string): boolean, string |
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: string |
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 -- luacheck: ignore 422 |
37 | for name, result in pairs(results) do -- luacheck: ignore 422 | 38 | for version, items in pairs(result) do -- luacheck: ignore 422 |
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 | -- Ignore provided rocks. |
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 | 56 | end |
57 | else | 57 | |
58 | local url | 58 | local rock = util.format_rock_name(name, namespace, version) |
59 | url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions) | 59 | return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") |
60 | if url then | 60 | end |
61 | return get_file(url) | 61 | |
62 | end | 62 | function download.download_file(arch: string, name: string, namespace?: string, version?: string, check_lua_versions?: boolean): string, string |
63 | local query = queries.new(name, namespace, version, false, arch) | ||
64 | local search_err: string | ||
65 | |||
66 | local url: string | ||
67 | url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions) | ||
68 | if url then | ||
69 | return get_file(url) | ||
63 | end | 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 ".") |
66 | end | 74 | end |