diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-08-23 19:34:00 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | bd1c9d3f2e2e289e5b0cf98a65381ef6ca8e4b07 (patch) | |
tree | 79f96aa67b7effb58de7dbfb0bcea8d098c39b1a | |
parent | 048edb8e011ce2e7e6910e305dc9a3242d319831 (diff) | |
download | luarocks-bd1c9d3f2e2e289e5b0cf98a65381ef6ca8e4b07.tar.gz luarocks-bd1c9d3f2e2e289e5b0cf98a65381ef6ca8e4b07.tar.bz2 luarocks-bd1c9d3f2e2e289e5b0cf98a65381ef6ca8e4b07.zip |
repos: simplify logic to avoid cast, consistent callback returns
-rw-r--r-- | src/luarocks/cmd/show.lua | 3 | ||||
-rw-r--r-- | src/luarocks/cmd/show.tl | 3 | ||||
-rw-r--r-- | src/luarocks/repos.lua | 35 | ||||
-rw-r--r-- | src/luarocks/repos.tl | 37 |
4 files changed, 47 insertions, 31 deletions
diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index 58d6701e..7f9ca9c6 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua | |||
@@ -206,12 +206,14 @@ local function modules_to_list(name, version, repo) | |||
206 | name = path.path_to_module(pathname), | 206 | name = path.path_to_module(pathname), |
207 | file = adjust_path(name, version, lua_dir, pathname), | 207 | file = adjust_path(name, version, lua_dir, pathname), |
208 | }) | 208 | }) |
209 | return true | ||
209 | end) | 210 | end) |
210 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname) | 211 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname) |
211 | table.insert(ret, { | 212 | table.insert(ret, { |
212 | name = path.path_to_module(pathname), | 213 | name = path.path_to_module(pathname), |
213 | file = adjust_path(name, version, lib_dir, pathname), | 214 | file = adjust_path(name, version, lib_dir, pathname), |
214 | }) | 215 | }) |
216 | return true | ||
215 | end) | 217 | end) |
216 | table.sort(ret, function(a, b) | 218 | table.sort(ret, function(a, b) |
217 | if a.name == b.name then | 219 | if a.name == b.name then |
@@ -232,6 +234,7 @@ local function commands_to_list(name, version, repo) | |||
232 | name = name, | 234 | name = name, |
233 | file = adjust_path(name, version, bin_dir, pathname, cfg.wrapper_suffix), | 235 | file = adjust_path(name, version, bin_dir, pathname, cfg.wrapper_suffix), |
234 | }) | 236 | }) |
237 | return true | ||
235 | end) | 238 | end) |
236 | table.sort(ret, function(a, b) | 239 | table.sort(ret, function(a, b) |
237 | if a.name == b.name then | 240 | if a.name == b.name then |
diff --git a/src/luarocks/cmd/show.tl b/src/luarocks/cmd/show.tl index 08dd9895..6063179a 100644 --- a/src/luarocks/cmd/show.tl +++ b/src/luarocks/cmd/show.tl | |||
@@ -206,12 +206,14 @@ local function modules_to_list(name: string, version: string, repo: string | Tre | |||
206 | name = path.path_to_module(pathname), | 206 | name = path.path_to_module(pathname), |
207 | file = adjust_path(name, version, lua_dir, pathname), | 207 | file = adjust_path(name, version, lua_dir, pathname), |
208 | }) | 208 | }) |
209 | return true | ||
209 | end) | 210 | end) |
210 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname: string): boolean, string | 211 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname: string): boolean, string |
211 | table.insert(ret, { | 212 | table.insert(ret, { |
212 | name = path.path_to_module(pathname), | 213 | name = path.path_to_module(pathname), |
213 | file = adjust_path(name, version, lib_dir, pathname), | 214 | file = adjust_path(name, version, lib_dir, pathname), |
214 | }) | 215 | }) |
216 | return true | ||
215 | end) | 217 | end) |
216 | table.sort(ret, function(a: Return, b: Return): boolean | 218 | table.sort(ret, function(a: Return, b: Return): boolean |
217 | if a.name == b.name then | 219 | if a.name == b.name then |
@@ -232,6 +234,7 @@ local function commands_to_list(name: string, version: string, repo: string | Tr | |||
232 | name = name, | 234 | name = name, |
233 | file = adjust_path(name, version, bin_dir, pathname, cfg.wrapper_suffix), | 235 | file = adjust_path(name, version, bin_dir, pathname, cfg.wrapper_suffix), |
234 | }) | 236 | }) |
237 | return true | ||
235 | end) | 238 | end) |
236 | table.sort(ret, function(a: Return, b: Return): boolean | 239 | table.sort(ret, function(a: Return, b: Return): boolean |
237 | if a.name == b.name then | 240 | if a.name == b.name then |
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 84c01815..956825e4 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
@@ -79,21 +79,19 @@ function repos.recurse_rock_manifest_entry(entry, action) | |||
79 | return true | 79 | return true |
80 | end | 80 | end |
81 | 81 | ||
82 | local function do_recurse_rock_manifest_entry(tree, parent_path) | 82 | local function do_recurse_rock_manifest_entry(tree, pathname) |
83 | 83 | if type(tree) == "string" then | |
84 | for file, sub in pairs(tree) do | 84 | return action(pathname) |
85 | local sub_path = (parent_path and (parent_path .. "/") or "") .. file | 85 | else |
86 | local ok, err | 86 | for file, sub in pairs(tree) do |
87 | 87 | local sub_path = pathname and dir.path(pathname, file) or file | |
88 | if type(sub) == "table" then | 88 | local ok, err = do_recurse_rock_manifest_entry(sub, sub_path) |
89 | ok, err = do_recurse_rock_manifest_entry(sub, sub_path) | 89 | if not ok then |
90 | else | 90 | return nil, err |
91 | ok, err = action(sub_path) | 91 | end |
92 | end | 92 | end |
93 | 93 | return true | |
94 | if err then return nil, err end | ||
95 | end | 94 | end |
96 | return true | ||
97 | end | 95 | end |
98 | return do_recurse_rock_manifest_entry(entry) | 96 | return do_recurse_rock_manifest_entry(entry) |
99 | end | 97 | end |
@@ -412,14 +410,15 @@ function repos.check_everything_is_installed(name, version, rock_manifest, repo, | |||
412 | if category == "bin" then | 410 | if category == "bin" then |
413 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) or | 411 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) or |
414 | (accept_versioned and (fs.exists(paths.v) or fs.exists(paths.v .. suffix))) then | 412 | (accept_versioned and (fs.exists(paths.v) or fs.exists(paths.v .. suffix))) then |
415 | return | 413 | return true |
416 | end | 414 | end |
417 | else | 415 | else |
418 | if fs.exists(paths.nv) or (accept_versioned and fs.exists(paths.v)) then | 416 | if fs.exists(paths.nv) or (accept_versioned and fs.exists(paths.v)) then |
419 | return | 417 | return true |
420 | end | 418 | end |
421 | end | 419 | end |
422 | table.insert(missing, paths.nv) | 420 | table.insert(missing, paths.nv) |
421 | return true | ||
423 | end) | 422 | end) |
424 | end | 423 | end |
425 | end | 424 | end |
@@ -481,6 +480,7 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
481 | target = target .. (cfg.wrapper_suffix or "") | 480 | target = target .. (cfg.wrapper_suffix or "") |
482 | end | 481 | end |
483 | table.insert(installs, { fn = install_binary, src = source, dst = target, backup = backup }) | 482 | table.insert(installs, { fn = install_binary, src = source, dst = target, backup = backup }) |
483 | return true | ||
484 | end) | 484 | end) |
485 | end | 485 | end |
486 | 486 | ||
@@ -500,6 +500,7 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
500 | local target = mode == "nv" and paths.nv or paths.v | 500 | local target = mode == "nv" and paths.nv or paths.v |
501 | local backup = name ~= cur_name or version ~= cur_version | 501 | local backup = name ~= cur_name or version ~= cur_version |
502 | table.insert(installs, { fn = move_lua, src = source, dst = target, backup = backup }) | 502 | table.insert(installs, { fn = move_lua, src = source, dst = target, backup = backup }) |
503 | return true | ||
503 | end) | 504 | end) |
504 | end | 505 | end |
505 | 506 | ||
@@ -519,6 +520,7 @@ function repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | |||
519 | local target = mode == "nv" and paths.nv or paths.v | 520 | local target = mode == "nv" and paths.nv or paths.v |
520 | local backup = name ~= cur_name or version ~= cur_version | 521 | local backup = name ~= cur_name or version ~= cur_version |
521 | table.insert(installs, { fn = move_lib, src = source, dst = target, backup = backup }) | 522 | table.insert(installs, { fn = move_lib, src = source, dst = target, backup = backup }) |
523 | return true | ||
522 | end) | 524 | end) |
523 | end | 525 | end |
524 | 526 | ||
@@ -613,6 +615,7 @@ function repos.delete_local_version(name, version, deps_mode, quick) | |||
613 | table.insert(renames, { src = next_paths.v, dst = next_paths.nv, suffix = cfg.wrapper_suffix }) | 615 | table.insert(renames, { src = next_paths.v, dst = next_paths.nv, suffix = cfg.wrapper_suffix }) |
614 | end | 616 | end |
615 | end | 617 | end |
618 | return true | ||
616 | end) | 619 | end) |
617 | end | 620 | end |
618 | 621 | ||
@@ -634,6 +637,7 @@ function repos.delete_local_version(name, version, deps_mode, quick) | |||
634 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) | 637 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) |
635 | end | 638 | end |
636 | end | 639 | end |
640 | return true | ||
637 | end) | 641 | end) |
638 | end | 642 | end |
639 | 643 | ||
@@ -655,6 +659,7 @@ function repos.delete_local_version(name, version, deps_mode, quick) | |||
655 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) | 659 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) |
656 | end | 660 | end |
657 | end | 661 | end |
662 | return true | ||
658 | end) | 663 | end) |
659 | end | 664 | end |
660 | 665 | ||
diff --git a/src/luarocks/repos.tl b/src/luarocks/repos.tl index 46458607..29645112 100644 --- a/src/luarocks/repos.tl +++ b/src/luarocks/repos.tl | |||
@@ -79,21 +79,19 @@ function repos.recurse_rock_manifest_entry(entry: Entry, action: (function(strin | |||
79 | return true | 79 | return true |
80 | end | 80 | end |
81 | 81 | ||
82 | local function do_recurse_rock_manifest_entry(tree: Entry, parent_path?: string): boolean, string | 82 | local function do_recurse_rock_manifest_entry(tree: Entry, pathname?: string): boolean, string |
83 | 83 | if tree is string then | |
84 | for file, sub in pairs(tree as {string: any}) do --! | 84 | return action(pathname) |
85 | local sub_path = (parent_path and (parent_path .. "/") or "") .. file | 85 | else |
86 | local ok, err: boolean, string -- luacheck: ignore 231 | 86 | for file, sub in pairs(tree) do |
87 | 87 | local sub_path = pathname and dir.path(pathname, file) or file | |
88 | if sub is Entry then | 88 | local ok, err = do_recurse_rock_manifest_entry(sub, sub_path) |
89 | ok, err = do_recurse_rock_manifest_entry(sub, sub_path) | 89 | if not ok then |
90 | else | 90 | return nil, err |
91 | ok, err = action(sub_path) | 91 | end |
92 | end | 92 | end |
93 | 93 | return true | |
94 | if err then return nil, err end | ||
95 | end | 94 | end |
96 | return true | ||
97 | end | 95 | end |
98 | return do_recurse_rock_manifest_entry(entry) | 96 | return do_recurse_rock_manifest_entry(entry) |
99 | end | 97 | end |
@@ -412,14 +410,15 @@ function repos.check_everything_is_installed(name: string, version: string, rock | |||
412 | if category == "bin" then | 410 | if category == "bin" then |
413 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) | 411 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) |
414 | or (accept_versioned and (fs.exists(paths.v) or fs.exists(paths.v .. suffix))) then | 412 | or (accept_versioned and (fs.exists(paths.v) or fs.exists(paths.v .. suffix))) then |
415 | return | 413 | return true |
416 | end | 414 | end |
417 | else | 415 | else |
418 | if fs.exists(paths.nv) or (accept_versioned and fs.exists(paths.v)) then | 416 | if fs.exists(paths.nv) or (accept_versioned and fs.exists(paths.v)) then |
419 | return | 417 | return true |
420 | end | 418 | end |
421 | end | 419 | end |
422 | table.insert(missing, paths.nv) | 420 | table.insert(missing, paths.nv) |
421 | return true | ||
423 | end) | 422 | end) |
424 | end | 423 | end |
425 | end | 424 | end |
@@ -481,6 +480,7 @@ function repos.deploy_local_files(name: string, version: string, wrap_bin_script | |||
481 | target = target .. (cfg.wrapper_suffix or "") | 480 | target = target .. (cfg.wrapper_suffix or "") |
482 | end | 481 | end |
483 | table.insert(installs, { fn = install_binary, src = source, dst = target, backup = backup }) | 482 | table.insert(installs, { fn = install_binary, src = source, dst = target, backup = backup }) |
483 | return true | ||
484 | end) | 484 | end) |
485 | end | 485 | end |
486 | 486 | ||
@@ -500,6 +500,7 @@ function repos.deploy_local_files(name: string, version: string, wrap_bin_script | |||
500 | local target = mode == "nv" and paths.nv or paths.v | 500 | local target = mode == "nv" and paths.nv or paths.v |
501 | local backup = name ~= cur_name or version ~= cur_version | 501 | local backup = name ~= cur_name or version ~= cur_version |
502 | table.insert(installs, { fn = move_lua, src = source, dst = target, backup = backup }) | 502 | table.insert(installs, { fn = move_lua, src = source, dst = target, backup = backup }) |
503 | return true | ||
503 | end) | 504 | end) |
504 | end | 505 | end |
505 | 506 | ||
@@ -519,6 +520,7 @@ function repos.deploy_local_files(name: string, version: string, wrap_bin_script | |||
519 | local target = mode == "nv" and paths.nv or paths.v | 520 | local target = mode == "nv" and paths.nv or paths.v |
520 | local backup = name ~= cur_name or version ~= cur_version | 521 | local backup = name ~= cur_name or version ~= cur_version |
521 | table.insert(installs, { fn = move_lib, src = source, dst = target, backup = backup }) | 522 | table.insert(installs, { fn = move_lib, src = source, dst = target, backup = backup }) |
523 | return true | ||
522 | end) | 524 | end) |
523 | end | 525 | end |
524 | 526 | ||
@@ -613,6 +615,7 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st | |||
613 | table.insert(renames, { src = next_paths.v, dst = next_paths.nv, suffix = cfg.wrapper_suffix }) | 615 | table.insert(renames, { src = next_paths.v, dst = next_paths.nv, suffix = cfg.wrapper_suffix }) |
614 | end | 616 | end |
615 | end | 617 | end |
618 | return true | ||
616 | end) | 619 | end) |
617 | end | 620 | end |
618 | 621 | ||
@@ -634,6 +637,7 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st | |||
634 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) | 637 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) |
635 | end | 638 | end |
636 | end | 639 | end |
640 | return true | ||
637 | end) | 641 | end) |
638 | end | 642 | end |
639 | 643 | ||
@@ -655,6 +659,7 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st | |||
655 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) | 659 | table.insert(renames, { src = next_lib_paths.v, dst = next_lib_paths.nv }) |
656 | end | 660 | end |
657 | end | 661 | end |
662 | return true | ||
658 | end) | 663 | end) |
659 | end | 664 | end |
660 | 665 | ||
@@ -687,4 +692,4 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st | |||
687 | return true, nil, "remove" | 692 | return true, nil, "remove" |
688 | end | 693 | end |
689 | 694 | ||
690 | return repos \ No newline at end of file | 695 | return repos |