]> git.ipfire.org Git - pakfire.git/commitdiff
build: Check for matching files in a loop
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Dec 2024 15:18:09 +0000 (15:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Dec 2024 15:18:09 +0000 (15:18 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/build.c

index d231b6cff25468995f86da8c136b738cc722dc55..08fa2160439e53ff6b49ded7efc2f1bc2149fb77 100644 (file)
@@ -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)