From 8f656b5a26c6c5352589e8ed294a8c27871b65a7 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 22 Aug 2024 17:48:59 -0300 Subject: Teal: convert luarocks.download --- src/luarocks/download.tl | 70 +++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'src') 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 @@ -local download = {} +local record download +end local path = require("luarocks.path") local fetch = require("luarocks.fetch") @@ -8,7 +9,7 @@ local fs = require("luarocks.fs") local dir = require("luarocks.dir") local util = require("luarocks.util") -local function get_file(filename) +local function get_file(filename: string): string, string local protocol, pathname = dir.split_url(filename) if protocol == "file" then local ok, err = fs.copy(pathname, fs.current_dir(), "read") @@ -24,43 +25,50 @@ local function get_file(filename) end end -function download.download(arch, name, namespace, version, all, check_lua_versions) - local substring = (all and name == "") +function download.download_all(arch: string, name: string, namespace: string, version: string): boolean, string + local substring = (name == "") local query = queries.new(name, namespace, version, substring, arch) - local search_err + local search_err: string - if all then - local results = search.search_repos(query) - local has_result = false - local all_ok = true - local any_err = "" - for name, result in pairs(results) do -- luacheck: ignore 422 - for version, items in pairs(result) do -- luacheck: ignore 422 - for _, item in ipairs(items) do - -- Ignore provided rocks. - if item.arch ~= "installed" then - has_result = true - local filename = path.make_url(item.repo, name, version, item.arch) - local ok, err = get_file(filename) - if not ok then - all_ok = false - any_err = any_err .. "\n" .. err - end + local results = search.search_repos(query) + local has_result = false + local all_ok = true + local any_err = "" + for name, result in pairs(results) do -- luacheck: ignore 422 + for version, items in pairs(result) do -- luacheck: ignore 422 + for _, item in ipairs(items) do + -- Ignore provided rocks. + if item.arch ~= "installed" then + has_result = true + local filename = path.make_url(item.repo, name, version, item.arch) + local ok, err = get_file(filename) + if not ok then + all_ok = false + any_err = any_err .. "\n" .. err end end end end + end - if has_result then - return all_ok, any_err - end - else - local url - url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions) - if url then - return get_file(url) - end + if has_result then + return all_ok, any_err + end + + local rock = util.format_rock_name(name, namespace, version) + return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") +end + +function download.download_file(arch: string, name: string, namespace?: string, version?: string, check_lua_versions?: boolean): string, string + local query = queries.new(name, namespace, version, false, arch) + local search_err: string + + local url: string + url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions) + if url then + return get_file(url) end + local rock = util.format_rock_name(name, namespace, version) return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") end -- cgit v1.2.3-55-g6feb