diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:04 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | aca7d0ad0bab3064fcb4598167e2fcd944242d76 (patch) | |
| tree | bfe8cd340ea957e2e08902e337386b3ea61677f2 /src | |
| parent | 97339f0e9542b96137f72c10333c86723d2b0a2d (diff) | |
| download | luarocks-aca7d0ad0bab3064fcb4598167e2fcd944242d76.tar.gz luarocks-aca7d0ad0bab3064fcb4598167e2fcd944242d76.tar.bz2 luarocks-aca7d0ad0bab3064fcb4598167e2fcd944242d76.zip | |
Teal: convert luarocks.cmd.unpack
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/unpack.tl (renamed from src/luarocks/cmd/unpack.lua) | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.tl index a0ade4f3..0e168785 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.tl | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | --- Module implementing the LuaRocks "unpack" command. | 2 | --- Module implementing the LuaRocks "unpack" command. |
| 3 | -- Unpack the contents of a rock. | 3 | -- Unpack the contents of a rock. |
| 4 | local unpack = {} | 4 | local record unpack |
| 5 | end | ||
| 5 | 6 | ||
| 6 | local fetch = require("luarocks.fetch") | 7 | local fetch = require("luarocks.fetch") |
| 7 | local fs = require("luarocks.fs") | 8 | local fs = require("luarocks.fs") |
| @@ -10,7 +11,13 @@ local build = require("luarocks.build") | |||
| 10 | local dir = require("luarocks.dir") | 11 | local dir = require("luarocks.dir") |
| 11 | local search = require("luarocks.search") | 12 | local search = require("luarocks.search") |
| 12 | 13 | ||
| 13 | function unpack.add_to_parser(parser) | 14 | local type Parser = require("luarocks.vendor.argparse").Parser |
| 15 | |||
| 16 | local type Args = require("luarocks.core.types.args").Args | ||
| 17 | |||
| 18 | local type Rockspec = require("luarocks.core.types.rockspec").Rockspec | ||
| 19 | |||
| 20 | function unpack.add_to_parser(parser: Parser) | ||
| 14 | local cmd = parser:command("unpack", [[ | 21 | local cmd = parser:command("unpack", [[ |
| 15 | Unpacks the contents of a rock in a newly created directory. | 22 | Unpacks the contents of a rock in a newly created directory. |
| 16 | Argument may be a rock file, or the name of a rock in a rocks server. | 23 | Argument may be a rock file, or the name of a rock in a rocks server. |
| @@ -34,9 +41,7 @@ end | |||
| 34 | -- @param dir_name string: The directory where to store and unpack files. | 41 | -- @param dir_name string: The directory where to store and unpack files. |
| 35 | -- @return table or (nil, string): the loaded rockspec table or | 42 | -- @return table or (nil, string): the loaded rockspec table or |
| 36 | -- nil and an error message. | 43 | -- nil and an error message. |
| 37 | local function unpack_rockspec(rockspec_file, dir_name) | 44 | local function unpack_rockspec(rockspec_file: string, dir_name: string): Rockspec, string |
| 38 | assert(type(rockspec_file) == "string") | ||
| 39 | assert(type(dir_name) == "string") | ||
| 40 | 45 | ||
| 41 | local rockspec, err = fetch.load_rockspec(rockspec_file) | 46 | local rockspec, err = fetch.load_rockspec(rockspec_file) |
| 42 | if not rockspec then | 47 | if not rockspec then |
| @@ -44,8 +49,8 @@ local function unpack_rockspec(rockspec_file, dir_name) | |||
| 44 | end | 49 | end |
| 45 | local ok, err = fs.change_dir(dir_name) | 50 | local ok, err = fs.change_dir(dir_name) |
| 46 | if not ok then return nil, err end | 51 | if not ok then return nil, err end |
| 47 | local ok, sources_dir = fetch.fetch_sources(rockspec, true, ".") | 52 | local filename, sources_dir = fetch.fetch_sources(rockspec, true, ".") |
| 48 | if not ok then | 53 | if not filename then |
| 49 | return nil, sources_dir | 54 | return nil, sources_dir |
| 50 | end | 55 | end |
| 51 | ok, err = fs.change_dir(sources_dir) | 56 | ok, err = fs.change_dir(sources_dir) |
| @@ -63,12 +68,11 @@ end | |||
| 63 | -- extension in the rock filename (eg. "src", "all", "linux-x86") | 68 | -- extension in the rock filename (eg. "src", "all", "linux-x86") |
| 64 | -- @return table or (nil, string): the loaded rockspec table or | 69 | -- @return table or (nil, string): the loaded rockspec table or |
| 65 | -- nil and an error message. | 70 | -- nil and an error message. |
| 66 | local function unpack_rock(rock_file, dir_name, kind) | 71 | local function unpack_rock(rock_file: string, dir_name: string, kind: string): Rockspec, string, string |
| 67 | assert(type(rock_file) == "string") | ||
| 68 | assert(type(dir_name) == "string") | ||
| 69 | 72 | ||
| 70 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) | 73 | local ok, filename, err, errcode: boolean, string, string, string |
| 71 | if not ok then | 74 | filename, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) |
| 75 | if not filename then | ||
| 72 | return nil, err, errcode | 76 | return nil, err, errcode |
| 73 | end | 77 | end |
| 74 | ok, err = fs.change_dir(dir_name) | 78 | ok, err = fs.change_dir(dir_name) |
| @@ -80,7 +84,7 @@ local function unpack_rock(rock_file, dir_name, kind) | |||
| 80 | end | 84 | end |
| 81 | if kind == "src" then | 85 | if kind == "src" then |
| 82 | if rockspec.source.file then | 86 | if rockspec.source.file then |
| 83 | local ok, err = fs.unpack_archive(rockspec.source.file) | 87 | ok, err = fs.unpack_archive(rockspec.source.file) |
| 84 | if not ok then return nil, err end | 88 | if not ok then return nil, err end |
| 85 | ok, err = fetch.find_rockspec_source_dir(rockspec, ".") | 89 | ok, err = fetch.find_rockspec_source_dir(rockspec, ".") |
| 86 | if not ok then return nil, err end | 90 | if not ok then return nil, err end |
| @@ -100,8 +104,7 @@ end | |||
| 100 | -- @param file string: A rockspec or .rock URL. | 104 | -- @param file string: A rockspec or .rock URL. |
| 101 | -- @return boolean or (nil, string): true if successful or nil followed | 105 | -- @return boolean or (nil, string): true if successful or nil followed |
| 102 | -- by an error message. | 106 | -- by an error message. |
| 103 | local function run_unpacker(file, force) | 107 | local function run_unpacker(file: string, force: boolean): boolean, string |
| 104 | assert(type(file) == "string") | ||
| 105 | 108 | ||
| 106 | local base_name = dir.base_name(file) | 109 | local base_name = dir.base_name(file) |
| 107 | local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$") | 110 | local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$") |
| @@ -123,7 +126,7 @@ local function run_unpacker(file, force) | |||
| 123 | end | 126 | end |
| 124 | local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) | 127 | local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) |
| 125 | 128 | ||
| 126 | local rockspec, err | 129 | local rockspec, err: Rockspec, string |
| 127 | if extension == "rock" then | 130 | if extension == "rock" then |
| 128 | rockspec, err = unpack_rock(file, dir_name, kind) | 131 | rockspec, err = unpack_rock(file, dir_name, kind) |
| 129 | elseif extension == "rockspec" then | 132 | elseif extension == "rockspec" then |
| @@ -152,8 +155,8 @@ end | |||
| 152 | --- Driver function for the "unpack" command. | 155 | --- Driver function for the "unpack" command. |
| 153 | -- @return boolean or (nil, string): true if successful or nil followed | 156 | -- @return boolean or (nil, string): true if successful or nil followed |
| 154 | -- by an error message. | 157 | -- by an error message. |
| 155 | function unpack.command(args) | 158 | function unpack.command(args: Args): boolean, string |
| 156 | local url, err | 159 | local url, err: string, string |
| 157 | if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then | 160 | if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then |
| 158 | url = args.rock | 161 | url = args.rock |
| 159 | else | 162 | else |
