aboutsummaryrefslogtreecommitdiff
path: root/cftw.c
Commit message (Collapse)AuthorAgeFilesLines
* cftw.c: Call user function at the end for directoriesXavier Del Campo Romero2025-10-061-12/+24
| | | | | | | | The older, synchronous implementation for cftw recursed as long as there were children directories and, finally, it called the user function. This commit therefore fixes the newer, asynchronous implementation to honor that behaviour. Otherwise, rmdir_r would fail because rmdir(2) would be called for non-empty directories.
* cftw.c: Fix memory leakXavier Del Campo Romero2025-09-241-0/+1
|
* Make search non-blockingXavier Del Campo Romero2025-09-241-55/+197
| | | | | | | | | | | | | Thanks to a new feature in libweb, it is now possible to generate HTTP responses asynchronously i.e., without blocking other clients if the response takes a long time to generate. This now allow users to search for files or directories without blocking other users, regardless how much time the search operation takes. This required cftw to deviate from the POSIX-like, blocking interface it had so far, and has been replaced now with a non-blocking interface, so that directories are inspected one entry at a time.
* cftw: Allow user callback to stop recursive searchXavier Del Campo Romero2023-07-111-6/+14
| | | | | | | | | | | | | | | So far, cftw would search through all directories and files recursively, until all objects are processed. However, it is interesting for the user callback to be able to stop this process under specific circumstances. Now, cftw will pass a pointer to a bool, initialised to false by default, that can be optionally assigned to true by the user callback. Future commits will make use of this feature. For example, this will be used to limit the number of search results when a user enters a search term that is too generic and would otherwise generate a large amount of search results.
* cftw: Allow directories to call the user callbackXavier Del Campo Romero2023-07-081-1/+6
| | | | | | | | This provides a few benefits: - This will allow searching for directories by name. - Future commits will allow to remove files and directories, so this change was also required for cftw.
* cftw.c: Check errors from readdir(3)Xavier Del Campo Romero2023-07-061-2/+12
| | | | | | According to POSIX.1-2017, applications are advised to assign errno(3) to 0 before a call to readdir(3), and compare errno(3) after the call to check for errors.
* ctfw.c: Avoid trailing forward slashXavier Del Campo Romero2023-06-061-1/+2
| | | | | | Otherwise, this would generate strings such as "directory//resource" if dirpath contained a trailing slash, which could be problematic for users relying on ctfw.
* cftw.c: Add missing portability definitionXavier Del Campo Romero2023-05-281-0/+2
|
* cftw.c: Add missing call to closedir(2)Xavier Del Campo Romero2023-03-071-4/+14
|
* Add cftwXavier Del Campo Romero2023-03-061-0/+61
POSIX functions ftw(3) and nftw(3) do not allow passing an opaque pointer to the callback they call, so it forces the use of statically allocated data. ctfw (from "custom ftw") is a custom implementation that solves this, while also removing unneeded stuff. This function will be used by future commits.