diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-28 20:04:39 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-29 12:50:56 -0300 |
| commit | ec44db639c2a84e488abf7f7fbd31872afadcb2c (patch) | |
| tree | 0086b48300f3e535d8a8ec4bbcc11d9447f92fed | |
| parent | f248b2e87ef8d97caaedbd36ed0f2c009aeedd1a (diff) | |
| download | luarocks-feat-better-perm-message.tar.gz luarocks-feat-better-perm-message.tar.bz2 luarocks-feat-better-perm-message.zip | |
feat: better error message when lacking permissionsfeat-better-perm-message
The lock error message has clobbered the check_command_permissions
error message. This is an interim solution, but we should probably
move the permissions check further up for a more informative error.
| -rw-r--r-- | spec/quick/build.q | 35 | ||||
| -rw-r--r-- | src/luarocks/cmd.lua | 13 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 5 |
3 files changed, 40 insertions, 13 deletions
diff --git a/spec/quick/build.q b/spec/quick/build.q index ee519adf..55bb7519 100644 --- a/spec/quick/build.q +++ b/spec/quick/build.q | |||
| @@ -83,8 +83,15 @@ RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec | |||
| 83 | EXIT: 4 | 83 | EXIT: 4 |
| 84 | STDERR: | 84 | STDERR: |
| 85 | -------------------------------------------------------------------------------- | 85 | -------------------------------------------------------------------------------- |
| 86 | requires exclusive access | 86 | requires exclusive write access |
| 87 | use --force-lock | 87 | -------------------------------------------------------------------------------- |
| 88 | |||
| 89 | We show the OS permission denied error, so we don't show the --force-lock | ||
| 90 | message. | ||
| 91 | |||
| 92 | NOT_STDERR: | ||
| 93 | -------------------------------------------------------------------------------- | ||
| 94 | try --force-lock | ||
| 88 | -------------------------------------------------------------------------------- | 95 | -------------------------------------------------------------------------------- |
| 89 | 96 | ||
| 90 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | 97 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec |
| @@ -93,8 +100,15 @@ RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec --force-lock | |||
| 93 | EXIT: 4 | 100 | EXIT: 4 |
| 94 | STDERR: | 101 | STDERR: |
| 95 | -------------------------------------------------------------------------------- | 102 | -------------------------------------------------------------------------------- |
| 96 | requires exclusive access | 103 | requires exclusive write access |
| 97 | failed to force the lock | 104 | -------------------------------------------------------------------------------- |
| 105 | |||
| 106 | We show the OS permission denied error, so we don't show the --force-lock | ||
| 107 | message. | ||
| 108 | |||
| 109 | NOT_STDERR: | ||
| 110 | -------------------------------------------------------------------------------- | ||
| 111 | try --force-lock | ||
| 98 | -------------------------------------------------------------------------------- | 112 | -------------------------------------------------------------------------------- |
| 99 | 113 | ||
| 100 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | 114 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec |
| @@ -108,8 +122,15 @@ RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec | |||
| 108 | EXIT: 4 | 122 | EXIT: 4 |
| 109 | STDERR: | 123 | STDERR: |
| 110 | -------------------------------------------------------------------------------- | 124 | -------------------------------------------------------------------------------- |
| 111 | requires exclusive access | 125 | requires exclusive write access |
| 112 | use --force-lock | 126 | -------------------------------------------------------------------------------- |
| 127 | |||
| 128 | We show the OS permission denied error, so we don't show the --force-lock | ||
| 129 | message. | ||
| 130 | |||
| 131 | NOT_STDERR: | ||
| 132 | -------------------------------------------------------------------------------- | ||
| 133 | try --force-lock | ||
| 113 | -------------------------------------------------------------------------------- | 134 | -------------------------------------------------------------------------------- |
| 114 | 135 | ||
| 115 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | 136 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec |
| @@ -118,7 +139,7 @@ RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec --force-lock | |||
| 118 | EXIT: 4 | 139 | EXIT: 4 |
| 119 | STDERR: | 140 | STDERR: |
| 120 | -------------------------------------------------------------------------------- | 141 | -------------------------------------------------------------------------------- |
| 121 | requires exclusive access | 142 | requires exclusive write access |
| 122 | failed to force the lock | 143 | failed to force the lock |
| 123 | -------------------------------------------------------------------------------- | 144 | -------------------------------------------------------------------------------- |
| 124 | 145 | ||
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index ca22c0db..b6d0d47e 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -732,12 +732,15 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 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 | lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock) | 733 | lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock) |
| 734 | if not lock then | 734 | if not lock then |
| 735 | local try_force = args.force_lock | 735 | err = args.force_lock |
| 736 | and (" - failed to force the lock" .. (err and ": " .. err or "")) | 736 | and ("failed to force the lock" .. (err and ": " .. err or "")) |
| 737 | or " - use --force-lock to overwrite the lock" | 737 | or (err and err ~= "File exists") |
| 738 | and err | ||
| 739 | or "try --force-lock to overwrite the lock" | ||
| 740 | |||
| 738 | die("command '" .. args.command .. "' " .. | 741 | die("command '" .. args.command .. "' " .. |
| 739 | "requires exclusive access to " .. path.root_dir(cfg.root_dir) .. | 742 | "requires exclusive write access to " .. path.root_dir(cfg.root_dir) .. " - " .. |
| 740 | try_force, cmd.errorcodes.LOCK) | 743 | err, cmd.errorcodes.LOCK) |
| 741 | end | 744 | end |
| 742 | end | 745 | end |
| 743 | 746 | ||
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index efd4d624..a0fba784 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
| @@ -319,7 +319,10 @@ function tools.is_superuser() | |||
| 319 | end | 319 | end |
| 320 | 320 | ||
| 321 | function tools.lock_access(dirname, force) | 321 | function tools.lock_access(dirname, force) |
| 322 | fs.make_dir(dirname) | 322 | local ok, err = fs.make_dir(dirname) |
| 323 | if not ok then | ||
| 324 | return nil, err | ||
| 325 | end | ||
| 323 | 326 | ||
| 324 | local tempfile = dir.path(dirname, ".lock.tmp." .. tostring(math.random(100000000))) | 327 | local tempfile = dir.path(dirname, ".lock.tmp." .. tostring(math.random(100000000))) |
| 325 | 328 | ||
