aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.
4local cache = {} 4local record cache
5end
5 6
6local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
7local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
8local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
9local util = require("luarocks.util") 10local util = require("luarocks.util")
10 11
11function cache.get_upload_server(server) 12function 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]
17end 18end
18 19
19function cache.get_server_urls(server, upload_server) 20function 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
33end 34end
34 35
35function cache.split_server_url(url, user, password) 36function 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
50end 51end
51 52
52local function download_cache(protocol, server_path, user, password) 53local 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
66end 67end
67 68
68function cache.refresh_local_cache(url, given_user, given_password) 69function 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)