#include <errno.h>
#include <stdlib.h>
+#include <pakfire/filelist.h>
#include <pakfire/pakfire.h>
#include <pakfire/string.h>
#include <pakfire/stripper.h>
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);
}
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)
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;
}