From: Michael Tremer Date: Mon, 21 Oct 2024 23:48:56 +0000 (+0000) Subject: stripper: Build scaffolding for a new stripper X-Git-Tag: 0.9.30~966 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1591ae64f49da7f9d77d289d32da2d57ad19837c;p=pakfire.git stripper: Build scaffolding for a new stripper Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index cae8ae886..88e004cd1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -229,6 +229,7 @@ libpakfire_la_SOURCES = \ src/libpakfire/snapshot.c \ src/libpakfire/solution.c \ src/libpakfire/string.c \ + src/libpakfire/stripper.c \ src/libpakfire/transaction.c \ src/libpakfire/util.c \ src/libpakfire/xfer.c @@ -282,6 +283,7 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/snapshot.h \ src/libpakfire/include/pakfire/solution.h \ src/libpakfire/include/pakfire/string.h \ + src/libpakfire/include/pakfire/stripper.h \ src/libpakfire/include/pakfire/transaction.h \ src/libpakfire/include/pakfire/util.h \ src/libpakfire/include/pakfire/xfer.h diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 521d8069b..716cf22bd 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -1323,6 +1324,27 @@ static int pakfire_build_run_post_build_scripts(struct pakfire_build* build) { return 0; } +static int pakfire_build_strip(struct pakfire_build* build) { + struct pakfire_stripper* stripper = NULL; + int r; + + // Create a new stripper + r = pakfire_stripper_create(&stripper, build->pakfire, build->buildroot); + if (r < 0) + goto ERROR; + + // Strip! + r = pakfire_stripper_run(stripper); + if (r < 0) + goto ERROR; + +ERROR: + if (stripper) + pakfire_stripper_unref(stripper); + + return r; +} + static void pakfire_build_free(struct pakfire_build* build) { if (build->packages) pakfire_packagelist_unref(build->packages); @@ -1810,6 +1832,11 @@ static int pakfire_build_perform(struct pakfire_build* build, if (r) goto ERROR; + // Run the stripper + r = pakfire_build_strip(build); + if (r < 0) + goto ERROR; + // Done! return 0; diff --git a/src/libpakfire/include/pakfire/stripper.h b/src/libpakfire/include/pakfire/stripper.h new file mode 100644 index 000000000..84d9dff0a --- /dev/null +++ b/src/libpakfire/include/pakfire/stripper.h @@ -0,0 +1,37 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2024 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_STRIPPER_H +#define PAKFIRE_STRIPPER_H + +#ifdef PAKFIRE_PRIVATE + +struct pakfire_stripper; + +int pakfire_stripper_create(struct pakfire_stripper** stripper, + struct pakfire* pakfire, const char* path); + +struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* stripper); +struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* stripper); + +int pakfire_stripper_run(struct pakfire_stripper* stripper); + +#endif /* PAKFIRE_PRIVATE */ +#endif /* PAKFIRE_STRIPPER_H */ diff --git a/src/libpakfire/stripper.c b/src/libpakfire/stripper.c new file mode 100644 index 000000000..d813294ad --- /dev/null +++ b/src/libpakfire/stripper.c @@ -0,0 +1,100 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include + +#include +#include +#include + +struct pakfire_stripper { + struct pakfire_ctx* ctx; + int nrefs; + + // Pakfire + struct pakfire* pakfire; + + // Path + char path[PATH_MAX]; + + // Filelist + struct pakfire_filelist* filelist; +}; + +int pakfire_stripper_create(struct pakfire_stripper** stripper, + struct pakfire* pakfire, const char* path) { + struct pakfire_stripper* s = NULL; + int r; + + // Allocate a new object + s = calloc(1, sizeof(*s)); + if (!s) + return -errno; + + // Store a reference to the context + s->ctx = pakfire_ctx(pakfire); + + // Store a reference to Pakfire + s->pakfire = pakfire_ref(pakfire); + + // Initialize the reference counter + s->nrefs = 1; + + // Store the path + r = pakfire_string_set(s->path, path); + if (r < 0) + goto ERROR; + + // Return the pointer + *stripper = pakfire_stripper_ref(s); + +ERROR: + if (s) + pakfire_stripper_unref(s); + + return r; +} + +static void pakfire_stripper_free(struct pakfire_stripper* stripper) { + if (stripper->pakfire) + pakfire_unref(stripper->pakfire); + if (stripper->ctx) + pakfire_ctx_unref(stripper->ctx); + free(stripper); +} + +struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* stripper) { + ++stripper->nrefs; + + return stripper; +} + +struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* stripper) { + if (--stripper->nrefs > 0) + return stripper; + + pakfire_stripper_free(stripper); + return NULL; +} + +int pakfire_stripper_run(struct pakfire_stripper* stripper) { + return 0; // TODO +}