perf(#3383): retrieve executable status from existing fs_stat.mode rather than a subsequent call to fs_access, file links show correct executable status #3399
lua doesn't have a nice way to use octal numbers
thx for picking this up! tested on macOS (arm64), found 2 things:
1. & breaks on stable nvim
stat.mode & 73 only parses on nightly as the LuaJIT bundled with stable doesn't support the 5.3 bitwise ops yet. So utils.lua fails to load and the tree doesn't open at all:
NVIM v0.12.7 / v0.10.4:
utils.lua:449: 'end' expected (to close 'if' at line 444) near '&'
Side note: CI is 🟢 cause check / lint don't actually load the module.
I'd use bit.band(stat.mode, 73) ~= 0, which works on 0.10.4, 0.12.7 and nightly just fine.
2. every symlink is now executable
fs_stat is an lstat, and on macOS a symlink's own mode is 0777 so the mask always hits. I think that using the target stat is a decent fix:
-- node/file.lua
self.executable = utils.is_executable(args.fs_stat_target or args.fs_stat)
-- explorer/init.lua reload
n.executable = utils.is_executable(n.fs_stat_target or stat)
Side note: fs_stat_target is from node creation so it can be a bit stale on reload if the target gets chmod'd, but that's kinda an edge case tbh 🤷♂️.
Some results: (fixture: plain 644, uexec 744, gexec 654, oexec 645, suid 4644, sticky 1644, link_exec -> uexec, link_plain -> plain)
| node | master | PR | PR + fixes |
|---|---|---|---|
| plain | false | false | false |
| uexec | true | true | true |
| gexec | false | true | true |
| oexec | false | true | true |
| suid / sticky | false | false | false |
| link_exec | true | true | true |
| link_plain | false | true | false |
(gexec/oexec flipping is the intended change i understood from your description. Same results on 0.10.4, 0.12.7 and 0.13.0-dev with the fixes)
stat.mode & 73only parses on nightly as the LuaJIT bundled with stable doesn't support the 5.3 bitwise ops yet. Soutils.luafails to load and the tree doesn't open at all:
That jit version seems quite variable, depending on how neovim was built and how it's packaged for the OS. It's fine on 0.12.6 for me.
I did wonder why we had the extra call to fs_access, lua versions do explain it.
I'd use bit.band(stat.mode, 73) ~= 0, which works on 0.10.4, 0.12.7 and nightly just fine.
bit.band should be the safe option - it's been used in neovim stable for over a year: https://github.com/neovim/neovim/blame/d2ca90d87e3246b5b827ed08f8c0dfc8ad6ae4c8/runtime/lua/vim/glob.lua#L234
Side note: CI is 🟢 cause check / lint don't actually load the module.
Functional tests are coming... #3369 I'd be really grateful if you could take a look at that branch.
2. every symlink is now executable
>fs_statis an lstat, and on macOS a symlink's own mode is0777so the mask always hits. I think that using the target stat is a decent fix:
Good catch! I didn't see that as the symlink hi group was overriding the executable one.
Link always has the target's stat so we can use that.
Many thanks for the review and test @hood
Changed:
A review / test would be most gratefully appreciated!
This was missing.
retested 692c6c44 on macOS, all good on 0.10.4, 0.12.7 and 0.13.0-dev! (results below)
| node | master | 692c6c44 |
|---|---|---|
| plain 644 | false | false |
| uexec 744 | true | true |
| gexec 654 / oexec 645 | false | true |
| suid / sticky | false | false |
| link_exec -> uexec | true | true |
| link_plain -> plain | false | false |
| dir (after reload) | true | false |
also tried doing chmod 755 plain + chmod 644 uexec with the tree open, then reloading: now plain, link_plain, uexec and link_exec all flip correctly, so update_fs_stat re-statting the target sorts out that staleness thing i mentioned. bonus: dirs don't go "executable" after a reload anymore!
LGTM! will have a go at #3369 on macOS too
LGTM! will have a go at #3369 on macOS too
Cheers mate
alex-courtis
fixes #3383
@hood I'd be grateful for your review and testing on macos
I've opted to return true for any executable bit, not just user as it was previously. This can be considered a bug.