From: Michael Tremer Date: Tue, 24 Dec 2024 15:18:09 +0000 (+0000) Subject: build: Check for matching files in a loop X-Git-Tag: 0.9.30~685 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bb11ba2ecfe5053af88755476d54c3746058299;p=pakfire.git build: Check for matching files in a loop When sending the filelist to scripts, we require the event loop to call us again and again. This seems to cause a deadlock situation and we now rather search for matching files in a loop until we have found a result (or not). Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index d231b6cff..08fa21604 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -345,48 +345,52 @@ static ssize_t pakfire_build_send_filelist( struct pakfire_ctx* ctx, void* data, char* buffer, size_t length) { struct pakfire_find_deps_ctx* p = (struct pakfire_find_deps_ctx*)data; struct pakfire_file* file = NULL; + const char* path = NULL; int r = 0; - // Check if we have reached the end of the filelist - if (p->i >= pakfire_filelist_length(p->filelist)) - return 0; + for (;;) { + // Check if we have reached the end of the filelist + if (p->i >= pakfire_filelist_length(p->filelist)) + return 0; - // Fetch the next file - file = pakfire_filelist_get(p->filelist, p->i); - if (!file) { - DEBUG(ctx, "Could not fetch file %u: %m\n", p->i); - r = -errno; - goto ERROR; - } + // Fetch the next file + file = pakfire_filelist_get(p->filelist, p->i); + if (!file) { + DEBUG(ctx, "Could not fetch file %u: %m\n", p->i); + r = -errno; + goto ERROR; + } - // Fetch the path of the file - const char* path = pakfire_file_get_path(file); - if (!path) { - ERROR(ctx, "Received a file with an empty path\n"); - r = -errno; - goto ERROR; - } + // Skip files that don't match what we are looking for + if (p->class && !pakfire_file_matches_class(file, p->class)) + goto SKIP; - // Skip files that don't match what we are looking for - if (p->class && !pakfire_file_matches_class(file, p->class)) { - r = -EAGAIN; - goto SKIP; - } + // Fetch the path of the file + path = pakfire_file_get_path(file); + if (!path) { + ERROR(ctx, "Received a file with an empty path\n"); + r = -errno; + goto ERROR; + } - // Write path to stdin - r = snprintf(buffer, length, "%s\n", path); - if (r < 0) - goto ERROR; + // Write path to the buffer + r = snprintf(buffer, length, "%s\n", path); + if (r < 0) + goto ERROR; - // If the output could not be written, we ask to be called again later - else if (r >= (ssize_t)length) { - r = -EAGAIN; - goto ERROR; - } + // If the output could not be written, we ask to be called again later + else if (r >= (ssize_t)length) { + r = -EAGAIN; + goto ERROR; + } SKIP: - // Move on to the next file - p->i++; + // Move on to the next file + p->i++; + + pakfire_file_unref(file); + file = NULL; + } ERROR: if (file)