luafilesystem icon indicating copy to clipboard operation
luafilesystem copied to clipboard

readlink() proposal

Open cehteh opened this issue 11 years ago • 4 comments

there is no 'readlink()' facility in luafilesystem. just having attributes() and symlinkattributes() is cumbersome to use.

I'd like to propose following ideas, and if accepted i can implement them and send a patch:

  • just implement lfs.readlink(name[, recursive]) which returns the file pointed too or 'nil' when not a symlink. If recursive is true or a number then resolve the link recursively (for n times or until reaching a final file, checking that there is no loop)
  • extend the lfs.attributes() function returning a .link field when the given filename was a link. This can be a array of recursive link expansions or just the final name to which it resolves. in case of a loop, stat() already fails.

cehteh avatar Jun 24 '14 16:06 cehteh

readlink() functionality was implemented as part of #78 (for non-Windows platforms). With an up-to-date LuaFileSystem you can access the symlink target via the new target attribute of symlinkattributes(), e.g.

lua -llfs -e 'print(lfs.symlinkattributes("/proc/self/exe", "target"))'

Regards, NiteHawk

n1tehawk avatar Oct 14 '16 13:10 n1tehawk

Side note: The documentation is still not mentioning the "target" attribute, as the relevant change to doc/us/manual.html has not been forwarded to the gh-pages branch yet.

n1tehawk avatar Oct 14 '16 14:10 n1tehawk

gh-pages is supposed to document latest release, not master

mpeterv avatar Oct 14 '16 15:10 mpeterv

Ah, I see - good point.

n1tehawk avatar Oct 14 '16 15:10 n1tehawk