]> git.ipfire.org Git - pakfire.git/commitdiff
stripper: Find all ELF files
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Oct 2024 00:09:37 +0000 (00:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Oct 2024 00:09:37 +0000 (00:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/stripper.c

index d813294adc3f160df4534070fb37f3bf3c049a4e..b8e9c84a5b1c74b6ed6d18e0e14f663240b6f07c 100644 (file)
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#include <pakfire/filelist.h>
 #include <pakfire/pakfire.h>
 #include <pakfire/string.h>
 #include <pakfire/stripper.h>
@@ -63,6 +64,11 @@ int pakfire_stripper_create(struct pakfire_stripper** stripper,
        if (r < 0)
                goto ERROR;
 
+       // Create a filelist
+       r = pakfire_filelist_create(&s->filelist, s->pakfire);
+       if (r < 0)
+               goto ERROR;
+
        // Return the pointer
        *stripper = pakfire_stripper_ref(s);
 
@@ -74,6 +80,8 @@ ERROR:
 }
 
 static void pakfire_stripper_free(struct pakfire_stripper* stripper) {
+       if (stripper->filelist)
+               pakfire_filelist_unref(stripper->filelist);
        if (stripper->pakfire)
                pakfire_unref(stripper->pakfire);
        if (stripper->ctx)
@@ -95,6 +103,63 @@ struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* strippe
        return NULL;
 }
 
+static int pakfire_stripper_find_elf(
+               struct pakfire* pakfire, struct pakfire_file* file, void* data) {
+       struct pakfire_stripper* stripper = data;
+       int r;
+
+       // Add ELF files to the filelist
+       if (pakfire_file_matches_class(file, PAKFIRE_FILE_ELF)) {
+               r = pakfire_filelist_add(stripper->filelist, file);
+               if (r < 0)
+                       return r;
+       }
+
+       return 0;
+}
+
+/*
+       Scan all files in path and identify ELF files
+*/
+static int pakfire_stripper_scan(struct pakfire_stripper* stripper) {
+       struct pakfire_filelist* filelist = NULL;
+       int r;
+
+       // Create a new filelist
+       r = pakfire_filelist_create(&filelist, stripper->pakfire);
+       if (r < 0)
+               goto ERROR;
+
+       // Scan path for all files
+       r = pakfire_filelist_scan(filelist, stripper->path, NULL, NULL, 0);
+       if (r < 0)
+               goto ERROR;
+
+       // Walk through all files to find ELF files
+       r = pakfire_filelist_walk(filelist, pakfire_stripper_find_elf, stripper, 0);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (filelist)
+               pakfire_filelist_unref(filelist);
+
+       return r;
+}
+
 int pakfire_stripper_run(struct pakfire_stripper* stripper) {
-       return 0; // TODO
+       int r;
+
+       // Scan for all ELF files in path
+       r = pakfire_stripper_scan(stripper);
+       if (r < 0)
+               return r;
+
+       // If the filelist is empty, there is nothing to do
+       if (pakfire_filelist_is_empty(stripper->filelist))
+               return 0;
+
+       // XXX TODO
+
+       return 0;
 }