diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:07 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | 0e3779ab9df1e36ab3933591cfe50d173df8ec8a (patch) | |
| tree | 084bf5bfeae30a6895de0f3cdffee7de0d28b608 /src | |
| parent | 194ea646d829572c4ef2a9fae35923aa49621d95 (diff) | |
| download | luarocks-0e3779ab9df1e36ab3933591cfe50d173df8ec8a.tar.gz luarocks-0e3779ab9df1e36ab3933591cfe50d173df8ec8a.tar.bz2 luarocks-0e3779ab9df1e36ab3933591cfe50d173df8ec8a.zip | |
Teal: convert luarocks.admin.cache
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/admin/cache.tl (renamed from src/luarocks/admin/cache.lua) | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/luarocks/admin/cache.lua b/src/luarocks/admin/cache.tl index 7a4e4af8..eb3b9568 100644 --- a/src/luarocks/admin/cache.lua +++ b/src/luarocks/admin/cache.tl | |||
| @@ -1,24 +1,25 @@ | |||
| 1 | 1 | ||
| 2 | --- Module handling the LuaRocks local cache. | 2 | --- Module handling the LuaRocks local cache. |
| 3 | -- Adds a rock or rockspec to a rocks server. | 3 | -- Adds a rock or rockspec to a rocks server. |
| 4 | local cache = {} | 4 | local record cache |
| 5 | end | ||
| 5 | 6 | ||
| 6 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
| 7 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
| 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 | function cache.get_upload_server(server) | 12 | function cache.get_upload_server(server: string): string, {string: string}, string |
| 12 | if not server then server = cfg.upload_server end | 13 | if not server then server = cfg.upload_server end |
| 13 | if not server then | 14 | if not server then |
| 14 | return nil, "No server specified and no default configured with upload_server." | 15 | return nil, nil, "No server specified and no default configured with upload_server." |
| 15 | end | 16 | end |
| 16 | return server, cfg.upload_servers and cfg.upload_servers[server] | 17 | return server, cfg.upload_servers and cfg.upload_servers[server] |
| 17 | end | 18 | end |
| 18 | 19 | ||
| 19 | function cache.get_server_urls(server, upload_server) | 20 | function cache.get_server_urls(server: string, upload_server: {string: string}): string, string |
| 20 | local download_url = server | 21 | local download_url: string = server |
| 21 | local login_url = nil | 22 | local login_url: string = nil |
| 22 | if upload_server then | 23 | if upload_server then |
| 23 | if upload_server.rsync then download_url = "rsync://"..upload_server.rsync | 24 | if upload_server.rsync then download_url = "rsync://"..upload_server.rsync |
| 24 | elseif upload_server.http then download_url = "http://"..upload_server.http | 25 | elseif upload_server.http then download_url = "http://"..upload_server.http |
| @@ -32,12 +33,12 @@ function cache.get_server_urls(server, upload_server) | |||
| 32 | return download_url, login_url | 33 | return download_url, login_url |
| 33 | end | 34 | end |
| 34 | 35 | ||
| 35 | function cache.split_server_url(url, user, password) | 36 | function cache.split_server_url(url: string, user: string, password: string): string, string, string, string, string |
| 36 | local protocol, server_path = dir.split_url(url) | 37 | local protocol, server_path = dir.split_url(url) |
| 37 | if protocol == "file" then | 38 | if protocol == "file" then |
| 38 | server_path = fs.absolute_name(server_path) | 39 | server_path = fs.absolute_name(server_path) |
| 39 | elseif server_path:match("@") then | 40 | elseif server_path:match("@") then |
| 40 | local credentials | 41 | local credentials: string |
| 41 | credentials, server_path = server_path:match("([^@]*)@(.*)") | 42 | credentials, server_path = server_path:match("([^@]*)@(.*)") |
| 42 | if credentials:match(":") then | 43 | if credentials:match(":") then |
| 43 | user, password = credentials:match("([^:]*):(.*)") | 44 | user, password = credentials:match("([^:]*):(.*)") |
| @@ -49,7 +50,7 @@ function cache.split_server_url(url, user, password) | |||
| 49 | return local_cache, protocol, server_path, user, password | 50 | return local_cache, protocol, server_path, user, password |
| 50 | end | 51 | end |
| 51 | 52 | ||
| 52 | local function download_cache(protocol, server_path, user, password) | 53 | local function download_cache(protocol: string, server_path: string, user: string, password: string): boolean, string, string |
| 53 | os.remove("index.html") | 54 | os.remove("index.html") |
| 54 | -- TODO abstract away explicit 'wget' call | 55 | -- TODO abstract away explicit 'wget' call |
| 55 | if protocol == "rsync" then | 56 | if protocol == "rsync" then |
| @@ -65,7 +66,7 @@ local function download_cache(protocol, server_path, user, password) | |||
| 65 | end | 66 | end |
| 66 | end | 67 | end |
| 67 | 68 | ||
| 68 | function cache.refresh_local_cache(url, given_user, given_password) | 69 | function cache.refresh_local_cache(url: string, given_user: string, given_password: string): string, string, string, string, string |
| 69 | local local_cache, protocol, server_path, user, password = cache.split_server_url(url, given_user, given_password) | 70 | local local_cache, protocol, server_path, user, password = cache.split_server_url(url, given_user, given_password) |
| 70 | 71 | ||
| 71 | local ok, err = fs.make_dir(local_cache) | 72 | local ok, err = fs.make_dir(local_cache) |
