From: Michael Tremer Date: Tue, 22 Oct 2024 00:09:37 +0000 (+0000) Subject: stripper: Find all ELF files X-Git-Tag: 0.9.30~963 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe878d82feb875edb39cc93a1f50fe53542a8f9c;p=pakfire.git stripper: Find all ELF files Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/stripper.c b/src/libpakfire/stripper.c index d813294ad..b8e9c84a5 100644 --- a/src/libpakfire/stripper.c +++ b/src/libpakfire/stripper.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -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; }