io 和 lfs 似乎都没有检查这个的选项。我需要使用此功能来模拟一些执行此检查的代码。
1 回答
It seems there's an undocumented permissions
field in the table returned by lfs.attributes()
. Thanks to @siffiejoe for pointing this out, didn't see it when I read the code.
Another approach is of course to try to read from the file, that will always work but might be slower.
You could also try opening the file and setting a (temporary, of course) read lock on it. Not sure about the portability of file locking in Lua, though.
Note: checking if a file is readable and then doing something can break due to race conditions; the permissions of a file can change between your check and the following action.