Project

General

Profile

Actions

Feature #3223

closed

Add readlink to lighty.c.* library functions

Added by flynn 6 months ago. Updated 5 months ago.

Status:
Fixed
Priority:
Normal
Category:
mod_magnet
Target version:
ASK QUESTIONS IN Forums:
No

Description

Currently I use external lua modules like lfs or posix only to have a readlink function.

I use the readlink function to resolve latest-softlinks to redirect the user to the current version of a download.

Please add readlink to the lighty.c in mod_magnet to avoid loading external modules only for one missing function.

Actions #1

Updated by gstrauss 6 months ago

  • Status changed from New to Need Feedback

symlinks are a *nix and POSIX feature, though not necessarily portable to Windows which inconsistently implements partial concepts in various versions of Windows.

You're asking for readlink() but not lstat()?

Also, note that lighty.c.stat() uses the lighttpd stat_cache (which can be configured to use inotify), and the lighttpd stat cache does not use lstat() except if configured to block symlinks (not recommended). Were lighttpd mod_magnet to provide direct interfaces to libc funcs (and uncached), that might suggest a lighty.libc.* namespace. In that case, what is the advantage to having lighttpd mod_magnet provide this versus lua lfs or posix modules?

While lighttpd mod_magnet could provide a lighty.libc.* namespace, you could write a small lua C module to do the same if for some reason you wanted to avoid the full lfs or posix modules.

Besides convenience, would you share the reasons behind this request? Is lfs or posix too large for your target memory use? Are there other reasons? Is there a performance hit? lighttpd caches lua scripts and you might look into requiring those modules in ways that does not re-execute those modules upon every request. lua provides multiple ways to include other code.

Actions #2

Updated by flynn 6 months ago

I'm definitly asking for readlink.

Windows does not support softlinks, but there is no need for readlink if I cannot create them, it can be excluded for Windows builds.

I didn't observe any performance issues, this is not what this ticket is about.

The main reason for this request is to avoid loading external modules if possible, especially if only one function is used:
  • more dependencies (maintenance, update, security issues)
  • bigger images
  • reduce SBOM

The history behind this is:
I used the the posix module to use readlink. After updating to Debian 12, the script failed, because lighttpd was updated to use lua version 5.4, but the Debian lua-posix package did not provide a 5.4 version module. I switch to lfs and changed the code. After looking in the lighty.libc.* I got the impression, that readlink is missing in the list file operations related functions: if you provide readdir, why not readlink?

Writing an own module creates maintenance and update issues as well, I see no difference using lfs or posix module.

This is a feature request, I did not provide a patch (maybe this made it easier for you), I can live with being rejected.

Actions #3

Updated by gstrauss 6 months ago

Thanks for the info. I'll think over the feature request.

Some of my comments above were aimed at documenting that the lighty.c.* interfaces are for lighttpd C internals, not directly libc functions. e.g. lighty.c.time() is cached inside lighttpd, not a call to libc and a system call; and lighty.c.stat() uses the lighttpd internal stat_cache.

if you provide readdir, why not readlink?

As I recall, I added readdir() when writing lua implementations of lighttpd C modules (e.g. mod_dirlisting) as examples or starting points for custom lua scripts, and I see a comment in the mod_magnet code about readdir() not being a part of lua io liolib.c.

readlink() is separate, as are lstat(), link(), and symlink(). I have no intention of reimplementing all of libc or lfs or posix, but will consider the feature request.

Actions #4

Updated by gstrauss 6 months ago

The lfs module supports lfs.symlinkattributes for lstat() and readlink() and supports making symlinks and hard links, too. The lfs module also supports some Windows equivalents/approximations.

I do not think that I want to duplicate such efforts into lighttpd mod_magnet, but will ruminate on it a bit further before deciding.

Actions #5

Updated by gstrauss 6 months ago

  • Status changed from Need Feedback to Patch Pending

I have some test code on my dev branch personal/gstrauss/master which implements lighty.c.readlink(). Simple on unix. Obnoxious, as is typical, on Windows.

Actions #6

Updated by gstrauss 6 months ago

  • Status changed from Patch Pending to Fixed
Actions #7

Updated by flynn 5 months ago

Thank you very much indeed!

Actions

Also available in: Atom