diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-03-04 12:17:56 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-03-05 15:58:45 +0000 |
commit | 78d40e304be182b7e07be449ebda668b8b9d0fcd (patch) | |
tree | 4df133a573797e77dc1eab3f47d6a42b37a9f91f /src | |
parent | 527b112738ce17fe93289ed879a2b84437fc5c40 (diff) | |
download | luarocks-78d40e304be182b7e07be449ebda668b8b9d0fcd.tar.gz luarocks-78d40e304be182b7e07be449ebda668b8b9d0fcd.tar.bz2 luarocks-78d40e304be182b7e07be449ebda668b8b9d0fcd.zip |
fix: check permissions before trying to lock
This should provide a better error message.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd.lua | 5 | ||||
-rw-r--r-- | src/luarocks/cmd/build.lua | 6 | ||||
-rw-r--r-- | src/luarocks/cmd/install.lua | 4 | ||||
-rw-r--r-- | src/luarocks/cmd/make.lua | 6 | ||||
-rw-r--r-- | src/luarocks/cmd/purge.lua | 5 | ||||
-rw-r--r-- | src/luarocks/cmd/remove.lua | 7 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 2 |
7 files changed, 8 insertions, 27 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index b6d0d47e..6085fc9d 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
@@ -730,6 +730,11 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
730 | 730 | ||
731 | local lock | 731 | local lock |
732 | if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then | 732 | if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then |
733 | local ok, err = fs.check_command_permissions(args) | ||
734 | if not ok then | ||
735 | die(err, cmd.errorcodes.PERMISSIONDENIED) | ||
736 | end | ||
737 | |||
733 | lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock) | 738 | lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock) |
734 | if not lock then | 739 | if not lock then |
735 | err = args.force_lock | 740 | err = args.force_lock |
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index 710c89f2..ada6b7d2 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua | |||
@@ -15,7 +15,6 @@ local build = require("luarocks.build") | |||
15 | local writer = require("luarocks.manif.writer") | 15 | local writer = require("luarocks.manif.writer") |
16 | local search = require("luarocks.search") | 16 | local search = require("luarocks.search") |
17 | local make = require("luarocks.cmd.make") | 17 | local make = require("luarocks.cmd.make") |
18 | local cmd = require("luarocks.cmd") | ||
19 | local repos = require("luarocks.repos") | 18 | local repos = require("luarocks.repos") |
20 | 19 | ||
21 | function cmd_build.add_to_parser(parser) | 20 | function cmd_build.add_to_parser(parser) |
@@ -156,11 +155,6 @@ function cmd_build.command(args) | |||
156 | end) | 155 | end) |
157 | end | 156 | end |
158 | 157 | ||
159 | local ok, err = fs.check_command_permissions(args) | ||
160 | if not ok then | ||
161 | return nil, err, cmd.errorcodes.PERMISSIONDENIED | ||
162 | end | ||
163 | |||
164 | local name, version, skip = do_build(args.rock, args.namespace, args.version, opts) | 158 | local name, version, skip = do_build(args.rock, args.namespace, args.version, opts) |
165 | if not name then | 159 | if not name then |
166 | return nil, version | 160 | return nil, version |
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index a6dddd2b..e71b6db8 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
@@ -13,7 +13,6 @@ local remove = require("luarocks.remove") | |||
13 | local search = require("luarocks.search") | 13 | local search = require("luarocks.search") |
14 | local queries = require("luarocks.queries") | 14 | local queries = require("luarocks.queries") |
15 | local cfg = require("luarocks.core.cfg") | 15 | local cfg = require("luarocks.core.cfg") |
16 | local cmd = require("luarocks.cmd") | ||
17 | 16 | ||
18 | function install.add_to_parser(parser) | 17 | function install.add_to_parser(parser) |
19 | local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 | 18 | local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 |
@@ -226,9 +225,6 @@ end | |||
226 | -- @return boolean or (nil, string, exitcode): True if installation was | 225 | -- @return boolean or (nil, string, exitcode): True if installation was |
227 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 226 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
228 | function install.command(args) | 227 | function install.command(args) |
229 | local ok, err = fs.check_command_permissions(args) | ||
230 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end | ||
231 | |||
232 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then | 228 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then |
233 | local build = require("luarocks.cmd.build") | 229 | local build = require("luarocks.cmd.build") |
234 | return build.command(args) | 230 | return build.command(args) |
diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index ef794b91..eaa4b899 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua | |||
@@ -6,7 +6,6 @@ | |||
6 | local make = {} | 6 | local make = {} |
7 | 7 | ||
8 | local build = require("luarocks.build") | 8 | local build = require("luarocks.build") |
9 | local fs = require("luarocks.fs") | ||
10 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
11 | local cfg = require("luarocks.core.cfg") | 10 | local cfg = require("luarocks.core.cfg") |
12 | local fetch = require("luarocks.fetch") | 11 | local fetch = require("luarocks.fetch") |
@@ -14,7 +13,6 @@ local pack = require("luarocks.pack") | |||
14 | local remove = require("luarocks.remove") | 13 | local remove = require("luarocks.remove") |
15 | local deps = require("luarocks.deps") | 14 | local deps = require("luarocks.deps") |
16 | local writer = require("luarocks.manif.writer") | 15 | local writer = require("luarocks.manif.writer") |
17 | local cmd = require("luarocks.cmd") | ||
18 | 16 | ||
19 | function make.cmd_options(parser) | 17 | function make.cmd_options(parser) |
20 | parser:flag("--no-install", "Do not install the rock.") | 18 | parser:flag("--no-install", "Do not install the rock.") |
@@ -126,9 +124,7 @@ function make.command(args) | |||
126 | return name, version | 124 | return name, version |
127 | end) | 125 | end) |
128 | else | 126 | else |
129 | local ok, err = fs.check_command_permissions(args) | 127 | local ok, err = build.build_rockspec(rockspec, opts) |
130 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end | ||
131 | ok, err = build.build_rockspec(rockspec, opts) | ||
132 | if not ok then return nil, err end | 128 | if not ok then return nil, err end |
133 | local name, version = ok, err -- luacheck: ignore 421 | 129 | local name, version = ok, err -- luacheck: ignore 421 |
134 | 130 | ||
diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua index 16d96531..30811ddf 100644 --- a/src/luarocks/cmd/purge.lua +++ b/src/luarocks/cmd/purge.lua | |||
@@ -4,7 +4,6 @@ | |||
4 | local purge = {} | 4 | local purge = {} |
5 | 5 | ||
6 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
7 | local fs = require("luarocks.fs") | ||
8 | local path = require("luarocks.path") | 7 | local path = require("luarocks.path") |
9 | local search = require("luarocks.search") | 8 | local search = require("luarocks.search") |
10 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
@@ -13,7 +12,6 @@ local writer = require("luarocks.manif.writer") | |||
13 | local cfg = require("luarocks.core.cfg") | 12 | local cfg = require("luarocks.core.cfg") |
14 | local remove = require("luarocks.remove") | 13 | local remove = require("luarocks.remove") |
15 | local queries = require("luarocks.queries") | 14 | local queries = require("luarocks.queries") |
16 | local cmd = require("luarocks.cmd") | ||
17 | 15 | ||
18 | function purge.add_to_parser(parser) | 16 | function purge.add_to_parser(parser) |
19 | -- luacheck: push ignore 431 | 17 | -- luacheck: push ignore 431 |
@@ -39,9 +37,6 @@ end | |||
39 | function purge.command(args) | 37 | function purge.command(args) |
40 | local tree = args.tree | 38 | local tree = args.tree |
41 | 39 | ||
42 | local ok, err = fs.check_command_permissions(args) | ||
43 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end | ||
44 | |||
45 | local results = {} | 40 | local results = {} |
46 | search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) | 41 | search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) |
47 | 42 | ||
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua index 91aa8914..8b11bcd3 100644 --- a/src/luarocks/cmd/remove.lua +++ b/src/luarocks/cmd/remove.lua | |||
@@ -6,13 +6,11 @@ local cmd_remove = {} | |||
6 | local remove = require("luarocks.remove") | 6 | local remove = require("luarocks.remove") |
7 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
8 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
9 | local fs = require("luarocks.fs") | ||
10 | local search = require("luarocks.search") | 9 | local search = require("luarocks.search") |
11 | local path = require("luarocks.path") | 10 | local path = require("luarocks.path") |
12 | local deps = require("luarocks.deps") | 11 | local deps = require("luarocks.deps") |
13 | local writer = require("luarocks.manif.writer") | 12 | local writer = require("luarocks.manif.writer") |
14 | local queries = require("luarocks.queries") | 13 | local queries = require("luarocks.queries") |
15 | local cmd = require("luarocks.cmd") | ||
16 | 14 | ||
17 | function cmd_remove.add_to_parser(parser) | 15 | function cmd_remove.add_to_parser(parser) |
18 | -- luacheck: push ignore 431 | 16 | -- luacheck: push ignore 431 |
@@ -43,9 +41,6 @@ function cmd_remove.command(args) | |||
43 | local name = args.rock | 41 | local name = args.rock |
44 | local deps_mode = deps.get_deps_mode(args) | 42 | local deps_mode = deps.get_deps_mode(args) |
45 | 43 | ||
46 | local ok, err = fs.check_command_permissions(args) | ||
47 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end | ||
48 | |||
49 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") | 44 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") |
50 | local version = args.version | 45 | local version = args.version |
51 | local filename = name | 46 | local filename = name |
@@ -63,7 +58,7 @@ function cmd_remove.command(args) | |||
63 | return nil, "Could not find rock '"..rock.."' in "..path.rocks_tree_to_string(cfg.root_dir) | 58 | return nil, "Could not find rock '"..rock.."' in "..path.rocks_tree_to_string(cfg.root_dir) |
64 | end | 59 | end |
65 | 60 | ||
66 | ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast) | 61 | local ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast) |
67 | if not ok then | 62 | if not ok then |
68 | return nil, err | 63 | return nil, err |
69 | end | 64 | end |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index a0fba784..16b31335 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -338,7 +338,7 @@ function tools.lock_access(dirname, force) | |||
338 | 338 | ||
339 | fd:close() | 339 | fd:close() |
340 | 340 | ||
341 | local lockfile = dir.path(dirname, "lockfile.luarocks") | 341 | local lockfile = dir.path(dirname, "lockfile.lfs") |
342 | 342 | ||
343 | local force_flag = force and " -f" or "" | 343 | local force_flag = force and " -f" or "" |
344 | 344 | ||