]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Move the filelist streaming helper from PTY
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Mar 2025 19:38:31 +0000 (19:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Mar 2025 19:38:31 +0000 (19:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c
src/pakfire/jail.c
src/pakfire/jail.h
src/pakfire/pty.c
src/pakfire/pty.h

index 56b5d993027c8b74790c167b79d07aa93b84dbaa..b540122d4db4722d25aaa67f01ab16e7a4cf22f0 100644 (file)
@@ -44,7 +44,6 @@
 #include <pakfire/parser.h>
 #include <pakfire/path.h>
 #include <pakfire/problem.h>
-#include <pakfire/pty.h>
 #include <pakfire/repo.h>
 #include <pakfire/scriptlet.h>
 #include <pakfire/solution.h>
@@ -820,19 +819,19 @@ static int pakfire_build_find_perl_deps(struct pakfire_build* build,
        if (r < 0)
                goto ERROR;
 
-       struct pakfire_pty_filelist input = {
+       struct pakfire_jail_filelist input = {
                .filelist = perlfiles,
        };
 
        // Find provides
        r = pakfire_build_run_script(build, "perl.prov", args,
-                       pakfire_pty_send_filelist, &input, pakfire_build_add_perl_provides, pkg);
+                       pakfire_jail_send_filelist, &input, pakfire_build_add_perl_provides, pkg);
        if (r < 0)
                goto ERROR;
 
        // Find requires
        r = pakfire_build_run_script(build, "perl.req", args,
-                       pakfire_pty_send_filelist, &input, pakfire_build_add_perl_requires, pkg);
+                       pakfire_jail_send_filelist, &input, pakfire_build_add_perl_requires, pkg);
        if (r < 0)
                goto ERROR;
 
index d91af07ce6f8ede6b01c0c149d7aa520cc577883..1a66065e2d9ead58c4eb5dfb511b6ff7b6f0b720 100644 (file)
@@ -2288,3 +2288,70 @@ ssize_t pakfire_jail_send_buffer(struct pakfire_ctx* ctx,
 
        return length;
 }
+
+ssize_t pakfire_jail_send_filelist(struct pakfire_ctx* ctx,
+               void* data, char* buffer, size_t length) {
+       struct pakfire_jail_filelist* input = data;
+       struct pakfire_file* file = NULL;
+       int r;
+
+       // If there is any path data left, we send that first
+       if (input->p) {
+               // How much data do we have left?
+               size_t l = strlen(input->p);
+
+               // Cap the length of the buffer
+               if (l < length)
+                       length = l;
+
+               memcpy(buffer, input->p, length);
+
+               // If we could not send all data, we will move the pointer forward
+               if (l > length)
+                       input->p += length;
+
+               // If we have sent all data, we reset the pointer
+               else if (l == length)
+                       input->p = NULL;
+
+               return length;
+       }
+
+       // Read the next file
+       file = pakfire_filelist_get(input->filelist, input->i++);
+
+       // If we could not fetch a file, we have reached the end of the list
+       if (!file) {
+               // Reset the counter so we can run again
+               input->i = 0;
+
+               return 0;
+       }
+
+       // Fetch the path
+       const char* path = pakfire_file_get_path(file);
+       if (!path) {
+               r = -EINVAL;
+               goto ERROR;
+       }
+
+       // Copy the path to the buffer
+       r = pakfire_string_format(input->buffer, "%s\n", path);
+       if (r < 0)
+               goto ERROR;
+
+       // Set the pointer to the start
+       input->p = input->buffer;
+
+       // Free the file
+       pakfire_file_unref(file);
+
+       // Send the buffer
+       return pakfire_jail_send_filelist(ctx, input, buffer, length);
+
+ERROR:
+       if (file)
+               pakfire_file_unref(file);
+
+       return r;
+}
index 2e2223c2119850fd4994edaa454e059c1fcc7884..7e6ace2c5cf00823db54274352d63fb2323afd82 100644 (file)
@@ -105,4 +105,18 @@ struct pakfire_input_buffer {
 ssize_t pakfire_jail_send_buffer(struct pakfire_ctx* ctx,
        void* data, char* buffer, size_t length);
 
+// Stream a filelist
+
+struct pakfire_jail_filelist {
+       struct pakfire_filelist* filelist;
+       size_t i;
+
+       // Buffer for the path
+       char buffer[PATH_MAX];
+       const char* p;
+};
+
+ssize_t pakfire_jail_send_filelist(struct pakfire_ctx* ctx,
+       void* data, char* buffer, size_t length);
+
 #endif /* PAKFIRE_JAIL_H */
index f35d2f6cfc4a64c302ed24cb4cd9c5ac1e533a42..7f49f874c3c48a9505ad2909a48c4c681f53a1ed 100644 (file)
@@ -1206,70 +1206,3 @@ int pakfire_pty_open(struct pakfire_pty* pty) {
 
        return 0;
 }
-
-ssize_t pakfire_pty_send_filelist(struct pakfire_ctx* ctx,
-               void* data, char* buffer, size_t length) {
-       struct pakfire_pty_filelist* input = data;
-       struct pakfire_file* file = NULL;
-       int r;
-
-       // If there is any path data left, we send that first
-       if (input->p) {
-               // How much data do we have left?
-               size_t l = strlen(input->p);
-
-               // Cap the length of the buffer
-               if (l < length)
-                       length = l;
-
-               memcpy(buffer, input->p, length);
-
-               // If we could not send all data, we will move the pointer forward
-               if (l > length)
-                       input->p += length;
-
-               // If we have sent all data, we reset the pointer
-               else if (l == length)
-                       input->p = NULL;
-
-               return length;
-       }
-
-       // Read the next file
-       file = pakfire_filelist_get(input->filelist, input->i++);
-
-       // If we could not fetch a file, we have reached the end of the list
-       if (!file) {
-               // Reset the counter so we can run again
-               input->i = 0;
-
-               return 0;
-       }
-
-       // Fetch the path
-       const char* path = pakfire_file_get_path(file);
-       if (!path) {
-               r = -EINVAL;
-               goto ERROR;
-       }
-
-       // Copy the path to the buffer
-       r = pakfire_string_format(input->buffer, "%s\n", path);
-       if (r < 0)
-               goto ERROR;
-
-       // Set the pointer to the start
-       input->p = input->buffer;
-
-       // Free the file
-       pakfire_file_unref(file);
-
-       // Send the buffer
-       return pakfire_pty_send_filelist(ctx, input, buffer, length);
-
-ERROR:
-       if (file)
-               pakfire_file_unref(file);
-
-       return r;
-}
index 50b246756556b54e6af393aac4aa089634f44147..6abde7368b2cd335d4e269ffefe82d14b018489b 100644 (file)
@@ -37,18 +37,4 @@ struct pakfire_pty* pakfire_pty_unref(struct pakfire_pty* pty);
 
 int pakfire_pty_open(struct pakfire_pty* pty);
 
-// Stream a filelist
-
-struct pakfire_pty_filelist {
-       struct pakfire_filelist* filelist;
-       size_t i;
-
-       // Buffer for the path
-       char buffer[PATH_MAX];
-       const char* p;
-};
-
-ssize_t pakfire_pty_send_filelist(struct pakfire_ctx* ctx,
-       void* data, char* buffer, size_t length);
-
 #endif /* PAKFIRE_PTY_H */