diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:06 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | 3ebe7058f649bb0045e844ba0c119ac9dd445d9b (patch) | |
tree | acd0db20667f8ce27940bf5d0f40f2c01d65bf8e | |
parent | f6e87b31d404f99b892b9a1e579b6932f47c6bca (diff) | |
download | luarocks-3ebe7058f649bb0045e844ba0c119ac9dd445d9b.tar.gz luarocks-3ebe7058f649bb0045e844ba0c119ac9dd445d9b.tar.bz2 luarocks-3ebe7058f649bb0045e844ba0c119ac9dd445d9b.zip |
Teal: convert luarocks.dir
-rw-r--r-- | src/luarocks/dir.tl (renamed from src/luarocks/dir.lua) | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.tl index be89e37b..e9e16fbd 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.tl | |||
@@ -1,6 +1,10 @@ | |||
1 | 1 | ||
2 | --- Generic utilities for handling pathnames. | 2 | --- Generic utilities for handling pathnames. |
3 | local dir = {} | 3 | local record dir |
4 | path: function(...: string): string | ||
5 | split_url: function(string): string, string | ||
6 | normalize: function(string): string | ||
7 | end | ||
4 | 8 | ||
5 | local core = require("luarocks.core.dir") | 9 | local core = require("luarocks.core.dir") |
6 | 10 | ||
@@ -14,10 +18,9 @@ local dir_sep = package.config:sub(1, 1) | |||
14 | -- @param pathname string: A path+name, such as "/a/b/c" | 18 | -- @param pathname string: A path+name, such as "/a/b/c" |
15 | -- or "\a\b\c". | 19 | -- or "\a\b\c". |
16 | -- @return string: The filename without its path, such as "c". | 20 | -- @return string: The filename without its path, such as "c". |
17 | function dir.base_name(pathname) | 21 | function dir.base_name(pathname: string): string |
18 | assert(type(pathname) == "string") | ||
19 | 22 | ||
20 | local b | 23 | local b: string |
21 | b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes | 24 | b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes |
22 | b = b:gsub("/*$", "") -- drop trailing slashes | 25 | b = b:gsub("/*$", "") -- drop trailing slashes |
23 | b = b:match(".*[/\\]([^/\\]*)") -- match last component | 26 | b = b:match(".*[/\\]([^/\\]*)") -- match last component |
@@ -31,10 +34,9 @@ end | |||
31 | -- @return string: The filename without its path, such as "/a/b". | 34 | -- @return string: The filename without its path, such as "/a/b". |
32 | -- For entries such as "/a/b/", "/a" is returned. If there are | 35 | -- For entries such as "/a/b/", "/a" is returned. If there are |
33 | -- no directory separators in input, "" is returned. | 36 | -- no directory separators in input, "" is returned. |
34 | function dir.dir_name(pathname) | 37 | function dir.dir_name(pathname: string): string |
35 | assert(type(pathname) == "string") | ||
36 | 38 | ||
37 | local d | 39 | local d: string |
38 | d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes | 40 | d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes |
39 | d = d:gsub("/*$", "") -- drop trailing slashes | 41 | d = d:gsub("/*$", "") -- drop trailing slashes |
40 | d = d:match("(.*)[/]+[^/]*") -- match all components but the last | 42 | d = d:match("(.*)[/]+[^/]*") -- match all components but the last |
@@ -46,11 +48,11 @@ end | |||
46 | 48 | ||
47 | --- Returns true if protocol does not require additional tools. | 49 | --- Returns true if protocol does not require additional tools. |
48 | -- @param protocol The protocol name | 50 | -- @param protocol The protocol name |
49 | function dir.is_basic_protocol(protocol) | 51 | function dir.is_basic_protocol(protocol: string): boolean |
50 | return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" | 52 | return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" |
51 | end | 53 | end |
52 | 54 | ||
53 | function dir.deduce_base_dir(url) | 55 | function dir.deduce_base_dir(url: string): string |
54 | -- for extensions like foo.tar.gz, "gz" is stripped first | 56 | -- for extensions like foo.tar.gz, "gz" is stripped first |
55 | local known_exts = {} | 57 | local known_exts = {} |
56 | for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do | 58 | for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do |