From 4fa1b3e89e1fc3902217c701711acd4d4c9ab01c Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 24 Sep 2025 15:46:24 +0200 Subject: thumbnail/main.c: Use new cftw interface This was a leftover from the following commit: commit 173528aef50a4b452acdd8ec9aff13f25c3e092c Author: Xavier Del Campo Romero Date: Wed Sep 24 11:01:31 2025 +0200 Make search non-blocking 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. --- thumbnail/main.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/thumbnail/main.c b/thumbnail/main.c index bbdc7f0..4629ff8 100644 --- a/thumbnail/main.c +++ b/thumbnail/main.c @@ -567,16 +567,33 @@ static int generate_existing(const char *const user, .force = force }; - printf("Scanning existing files...\n"); + int ret = -1; + enum cftw_state state; + struct cftw *const c = cftw(user, do_generate, &a); - if (cftw(user, do_generate, &a)) + if (!c) { fprintf(stderr, "%s: cftw failed\n", __func__); - return -1; + goto end; + } + + printf("Scanning existing files...\n"); + + while ((state = cftw_step(c)) == CFTW_AGAIN) + ; + + if (state) + { + fprintf(stderr, "%s: cftw_step failed\n", __func__); + goto end; } printf("Finished scanning\n"); - return 0; + cftw_free(c); + ret = 0; + +end: + return ret; } static void handle_signal(const int signum) -- cgit v1.2.3