Skip to content

stat/lstat confusion in posix lua module #3719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
keszybz opened this issue Apr 16, 2025 · 2 comments
Open

stat/lstat confusion in posix lua module #3719

keszybz opened this issue Apr 16, 2025 · 2 comments
Labels
lua Lua bindings/interface

Comments

@keszybz
Copy link
Contributor

keszybz commented Apr 16, 2025

posix.stat implements lstat that doesn't follow symlinks. Normal stat that follows symlinks is not available. The first issue is that people would expect stat to provide the semantics of stat, and get unexpected results. The second issue is that stat is not available.

$  strace -y rpmlua -e 'print(posix.stat("/usr/local/sbin").type)' |& rg /usr/local/sbin
newfstatat(AT_FDCWD</home/zbyszek/src/rpm>, "/usr/local/sbin", {st_mode=S_IFLNK|0777, st_size=3, ...}, AT_SYMLINK_NOFOLLOW) = 0

AT_SYMLINK_NOFOLLOW means that this implements lstat semantics.

@dmnks dmnks added this to RPM Apr 22, 2025
@github-project-automation github-project-automation bot moved this to Backlog in RPM Apr 22, 2025
@dmnks dmnks added the lua Lua bindings/interface label Apr 22, 2025
@pmatilai
Copy link
Member

Seems we negletted to comment here.

It's an interesting case. posix.stat() has been unconditionally using lstat() underneath ever since its addition in 2004. Kinda amazing that it took 21 years for anybody to notice, or at least, complain. Sometimes you need lstat() and sometimes you need stat(), and obviously we should provide access to both. It's just that at this point we cannot touch the existing posix.stat() because who knows what disasters may occur.

We could add a flag argument to change the meaning but it'd be kinda reverse from what you expect. Alternatively we'd need to come up with some other name for the thing.

@keszybz
Copy link
Contributor Author

keszybz commented May 29, 2025

I agree that touching the existing function is not a good idea.

Ideas for naming:

  • add posix.posix_lstat and posix.posix_stat
  • add posix.stat_follow and posix.stat_nofollow
  • add just posix.stat_follow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lua Lua bindings/interface
Projects
Status: Backlog
Development

No branches or pull requests

3 participants