From df302d44df3851a79ca8e5b4cd088ef2e1d8fb62 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 22 Aug 2024 17:48:59 -0300 Subject: Teal: rename luarocks.download --- src/luarocks/download.lua | 68 ----------------------------------------------- src/luarocks/download.tl | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 68 deletions(-) delete mode 100644 src/luarocks/download.lua create mode 100644 src/luarocks/download.tl diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua deleted file mode 100644 index 07a2a65f..00000000 --- a/src/luarocks/download.lua +++ /dev/null @@ -1,68 +0,0 @@ -local download = {} - -local path = require("luarocks.path") -local fetch = require("luarocks.fetch") -local search = require("luarocks.search") -local queries = require("luarocks.queries") -local fs = require("luarocks.fs") -local dir = require("luarocks.dir") -local util = require("luarocks.util") - -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(), "read") - if ok then - return pathname - else - return nil, err - end - else - -- discard third result - local ok, err = fetch.fetch_url(filename) - return ok, err - end -end - -function download.download(arch, name, namespace, version, all, check_lua_versions) - local substring = (all and name == "") - local query = queries.new(name, namespace, version, substring, arch) - local search_err - - 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 - 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 - 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 - -return download diff --git a/src/luarocks/download.tl b/src/luarocks/download.tl new file mode 100644 index 00000000..07a2a65f --- /dev/null +++ b/src/luarocks/download.tl @@ -0,0 +1,68 @@ +local download = {} + +local path = require("luarocks.path") +local fetch = require("luarocks.fetch") +local search = require("luarocks.search") +local queries = require("luarocks.queries") +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local util = require("luarocks.util") + +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(), "read") + if ok then + return pathname + else + return nil, err + end + else + -- discard third result + local ok, err = fetch.fetch_url(filename) + return ok, err + end +end + +function download.download(arch, name, namespace, version, all, check_lua_versions) + local substring = (all and name == "") + local query = queries.new(name, namespace, version, substring, arch) + local search_err + + 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 + 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 + 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 + +return download -- cgit v1.2.3-55-g6feb