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 | |
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.
-rw-r--r-- | spec/quick/build.q | 76 | ||||
-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 |
8 files changed, 60 insertions, 51 deletions
diff --git a/spec/quick/build.q b/spec/quick/build.q index 55bb7519..7cbc526b 100644 --- a/spec/quick/build.q +++ b/spec/quick/build.q | |||
@@ -79,11 +79,16 @@ a_rock 1.0 | |||
79 | ================================================================================ | 79 | ================================================================================ |
80 | TEST: fails if no permissions to access the specified tree #unix | 80 | TEST: fails if no permissions to access the specified tree #unix |
81 | 81 | ||
82 | RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec | 82 | RUN: luarocks build --tree=/usr ./a_rock-1.0-1.rockspec |
83 | EXIT: 4 | 83 | EXIT: 2 |
84 | STDERR: | 84 | STDERR: |
85 | -------------------------------------------------------------------------------- | 85 | -------------------------------------------------------------------------------- |
86 | requires exclusive write access | 86 | You may want to run as a privileged user, |
87 | or use --local to install into your local tree | ||
88 | or run 'luarocks config local_by_default true' to make --local the default. | ||
89 | |||
90 | (You may need to configure your Lua package paths | ||
91 | to use the local tree, see 'luarocks path --help') | ||
87 | -------------------------------------------------------------------------------- | 92 | -------------------------------------------------------------------------------- |
88 | 93 | ||
89 | We show the OS permission denied error, so we don't show the --force-lock | 94 | We show the OS permission denied error, so we don't show the --force-lock |
@@ -96,33 +101,66 @@ try --force-lock | |||
96 | 101 | ||
97 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | 102 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec |
98 | 103 | ||
99 | RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec --force-lock | 104 | |
100 | EXIT: 4 | 105 | |
101 | STDERR: | 106 | ================================================================================ |
107 | TEST: fails if tree is locked, --force-lock overrides #unix | ||
108 | |||
109 | FILE: a_rock-1.0-1.rockspec | ||
102 | -------------------------------------------------------------------------------- | 110 | -------------------------------------------------------------------------------- |
103 | requires exclusive write access | 111 | rockspec_format = "3.0" |
112 | package = "a_rock" | ||
113 | version = "1.0-1" | ||
114 | source = { | ||
115 | url = "file://%{url(%{fixtures_dir})}/a_rock.lua" | ||
116 | } | ||
117 | description = { | ||
118 | summary = "An example rockspec", | ||
119 | } | ||
120 | dependencies = { | ||
121 | "lua >= 5.1" | ||
122 | } | ||
123 | build = { | ||
124 | modules = { | ||
125 | build = "a_rock.lua" | ||
126 | }, | ||
127 | } | ||
104 | -------------------------------------------------------------------------------- | 128 | -------------------------------------------------------------------------------- |
105 | 129 | ||
106 | We show the OS permission denied error, so we don't show the --force-lock | 130 | FILE: %{testing_tree}/lockfile.lfs |
107 | message. | 131 | -------------------------------------------------------------------------------- |
132 | dummy lock file for testing | ||
133 | -------------------------------------------------------------------------------- | ||
108 | 134 | ||
109 | NOT_STDERR: | 135 | RUN: luarocks build --tree=%{testing_tree} ./a_rock-1.0-1.rockspec |
136 | EXIT: 4 | ||
137 | STDERR: | ||
110 | -------------------------------------------------------------------------------- | 138 | -------------------------------------------------------------------------------- |
139 | requires exclusive write access | ||
111 | try --force-lock | 140 | try --force-lock |
112 | -------------------------------------------------------------------------------- | 141 | -------------------------------------------------------------------------------- |
113 | 142 | ||
114 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | 143 | RUN: luarocks build --tree=%{testing_tree} ./a_rock-1.0-1.rockspec --force-lock |
144 | EXIT: 0 | ||
115 | 145 | ||
116 | 146 | ||
117 | 147 | ||
118 | ================================================================================ | 148 | ================================================================================ |
119 | TEST: fails if no permissions to access the parent #unix | 149 | TEST: fails if no permissions to access the parent #unix |
120 | 150 | ||
121 | RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec | 151 | RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0-1.rockspec |
122 | EXIT: 4 | 152 | EXIT: 2 |
123 | STDERR: | 153 | STDERR: |
124 | -------------------------------------------------------------------------------- | 154 | -------------------------------------------------------------------------------- |
125 | requires exclusive write access | 155 | Error: /usr/invalid/lib/luarocks/rocks-%{lua_version} does not exist |
156 | and your user does not have write permissions in /usr | ||
157 | |||
158 | You may want to run as a privileged user, | ||
159 | or use --local to install into your local tree | ||
160 | or run 'luarocks config local_by_default true' to make --local the default. | ||
161 | |||
162 | (You may need to configure your Lua package paths | ||
163 | to use the local tree, see 'luarocks path --help') | ||
126 | -------------------------------------------------------------------------------- | 164 | -------------------------------------------------------------------------------- |
127 | 165 | ||
128 | We show the OS permission denied error, so we don't show the --force-lock | 166 | We show the OS permission denied error, so we don't show the --force-lock |
@@ -135,16 +173,6 @@ try --force-lock | |||
135 | 173 | ||
136 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | 174 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec |
137 | 175 | ||
138 | RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec --force-lock | ||
139 | EXIT: 4 | ||
140 | STDERR: | ||
141 | -------------------------------------------------------------------------------- | ||
142 | requires exclusive write access | ||
143 | failed to force the lock | ||
144 | -------------------------------------------------------------------------------- | ||
145 | |||
146 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | ||
147 | |||
148 | 176 | ||
149 | 177 | ||
150 | ================================================================================ | 178 | ================================================================================ |
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 | ||