From 15d5287602ef57c6e4d00ae650ed2f49b71664cd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 25 Oct 2024 10:16:19 +0000 Subject: [PATCH] filelist: Change walk callback to refer to the context Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 25 ++++++++++------------- src/libpakfire/compress.c | 10 ++++----- src/libpakfire/filelist.c | 18 +++++++--------- src/libpakfire/include/pakfire/filelist.h | 5 ++++- src/libpakfire/package.c | 10 ++++----- src/libpakfire/packager.c | 6 +++--- src/libpakfire/stripper.c | 15 ++++++-------- 7 files changed, 41 insertions(+), 48 deletions(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index ca356ec84..37993821f 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -588,8 +588,8 @@ ERROR: } static int __pakfire_build_package_mark_config_files( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { - char** configfiles = (char**)data; + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { + char** configfiles = data; int r; // Skip anything that isn't a regular file @@ -1077,8 +1077,7 @@ enum { */ static int pakfire_build_post_process_files(struct pakfire_build* build, struct pakfire_filelist* filelist, const char* description, - int (*callback)(struct pakfire* pakfire, struct pakfire_file* file, void* data), - int flags) { + pakfire_filelist_walk_callback callback, int flags) { struct pakfire_filelist* removees = NULL; int r; @@ -1125,7 +1124,7 @@ ERROR: } static int __pakfire_build_remove_static_libraries( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_filelist* removees = (struct pakfire_filelist*)data; char path[PATH_MAX]; int r; @@ -1159,7 +1158,7 @@ static int pakfire_build_post_remove_static_libraries( } static int __pakfire_build_remove_libtool_archives( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_filelist* removees = (struct pakfire_filelist*)data; // Find all libtool archive files @@ -1178,7 +1177,7 @@ static int pakfire_build_post_remove_libtool_archives( } static int __pakfire_build_check_broken_symlinks( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_filelist* broken = (struct pakfire_filelist*)data; int r; @@ -1214,7 +1213,7 @@ static int pakfire_build_post_check_broken_symlinks( */ static int __pakfire_build_post_check_files( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_filelist* broken = (struct pakfire_filelist*)data; int issues = 0; int r; @@ -1845,13 +1844,11 @@ ERROR: return r; } -static int __pakfire_build_unpackaged_file(struct pakfire* pakfire, - struct pakfire_file* file, void* p) { - struct pakfire_build* build = p; - +static int __pakfire_build_unpackaged_file( + struct pakfire_ctx* ctx, struct pakfire_file* file, void* p) { char* s = pakfire_file_dump(file, PAKFIRE_FILE_DUMP_FULL); if (s) { - CTX_ERROR(build->ctx, "%s\n", s); + CTX_ERROR(ctx, "%s\n", s); free(s); } @@ -1875,7 +1872,7 @@ static int pakfire_build_check_unpackaged_files(struct pakfire_build* build) { if (!pakfire_filelist_is_empty(filelist)) { CTX_ERROR(build->ctx, "Unpackaged files found:\n"); - r = pakfire_filelist_walk(filelist, __pakfire_build_unpackaged_file, build, 0); + r = pakfire_filelist_walk(filelist, __pakfire_build_unpackaged_file, NULL, 0); if (r) goto ERROR; diff --git a/src/libpakfire/compress.c b/src/libpakfire/compress.c index df24650e2..fb06916e5 100644 --- a/src/libpakfire/compress.c +++ b/src/libpakfire/compress.c @@ -581,7 +581,7 @@ static int pakfire_copy_data_from_file(struct pakfire_ctx* ctx, return 0; } -static int __pakfire_compress_entry(struct pakfire* pakfire, struct pakfire_file* file, +static int __pakfire_compress_entry(struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_compress* data, struct archive_entry* entry) { FILE* f = NULL; int r; @@ -629,7 +629,7 @@ ERROR: return r; } -static int __pakfire_compress(struct pakfire* pakfire, struct pakfire_file* file, void* p) { +static int __pakfire_compress(struct pakfire_ctx* ctx, struct pakfire_file* file, void* p) { struct archive_entry* entry = NULL; struct archive_entry* sparse_entry = NULL; int r = 1; @@ -651,14 +651,14 @@ static int __pakfire_compress(struct pakfire* pakfire, struct pakfire_file* file // Write the main entry if (entry) { - r = __pakfire_compress_entry(pakfire, file, data, entry); + r = __pakfire_compress_entry(ctx, file, data, entry); if (r) goto ERROR; } // Write the sparse entry if (sparse_entry) { - r = __pakfire_compress_entry(pakfire, file, data, sparse_entry); + r = __pakfire_compress_entry(ctx, file, data, sparse_entry); if (r) goto ERROR; } @@ -683,7 +683,7 @@ static int __pakfire_compress(struct pakfire* pakfire, struct pakfire_file* file break; // Write the entry to the archive - r = __pakfire_compress_entry(pakfire, file, data, entry); + r = __pakfire_compress_entry(ctx, file, data, entry); if (r) goto ERROR; } diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index f68234416..5dd3994be 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -211,7 +211,7 @@ static int pakfire_filelist_remove(struct pakfire_filelist* list, struct pakfire } static int __pakfire_filelist_remove_one( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_filelist* list = (struct pakfire_filelist*)data; // Remove the file from the given filelist @@ -464,7 +464,7 @@ int pakfire_filelist_walk(struct pakfire_filelist* list, pakfire_progress_increment(progress, 1); // Call the callback - r = callback(list->pakfire, element->file, data); + r = callback(list->ctx, element->file, data); if (r) break; } @@ -485,10 +485,8 @@ ERROR: } static int __pakfire_filelist_dump( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { - int* flags = (int*)data; - - struct pakfire_ctx* ctx = pakfire_ctx(pakfire); + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { + int* flags = data; char* s = pakfire_file_dump(file, *flags); if (s) { @@ -496,8 +494,6 @@ static int __pakfire_filelist_dump( free(s); } - pakfire_ctx_unref(ctx); - return 0; } @@ -585,9 +581,9 @@ int pakfire_filelist_cleanup(struct pakfire_filelist* list, int flags) { return 0; } -static int __pakfire_filelist_matches_class(struct pakfire* pakfire, - struct pakfire_file* file, void* p) { - int* class = (int*)p; +static int __pakfire_filelist_matches_class( + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { + int* class = data; return pakfire_file_matches_class(file, *class); } diff --git a/src/libpakfire/include/pakfire/filelist.h b/src/libpakfire/include/pakfire/filelist.h index 835610751..4f1d93301 100644 --- a/src/libpakfire/include/pakfire/filelist.h +++ b/src/libpakfire/include/pakfire/filelist.h @@ -24,6 +24,7 @@ struct pakfire_filelist; #include +#include int pakfire_filelist_create(struct pakfire_filelist** list, struct pakfire* pakfire); @@ -42,6 +43,8 @@ int pakfire_filelist_add(struct pakfire_filelist* list, struct pakfire_file* fil #include +#include + size_t pakfire_filelist_total_size(struct pakfire_filelist* list); int pakfire_filelist_remove_all(struct pakfire_filelist* list, @@ -58,7 +61,7 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, int pakfire_filelist_contains(struct pakfire_filelist* list, const char* pattern); typedef int (*pakfire_filelist_walk_callback) - (struct pakfire* pakfire, struct pakfire_file* file, void* data); + (struct pakfire_ctx* ctx, struct pakfire_file* file, void* data); enum pakfire_filelist_walk_flags { PAKFIRE_FILELIST_SHOW_PROGRESS = (1 << 0), diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 225661f2e..50e2cfb79 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -1970,9 +1970,9 @@ int pakfire_package_append_file(struct pakfire_package* pkg, const char* path) { return 0; } -static int __pakfire_package_set_filelist(struct pakfire* pakfire, - struct pakfire_file* file, void* data) { - struct pakfire_package* pkg = (struct pakfire_package*)data; +static int __pakfire_package_set_filelist( + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { + struct pakfire_package* pkg = data; // Fetch the path const char* path = pakfire_file_get_path(file); @@ -2108,8 +2108,8 @@ ERROR: return r; } -static int __pakfire_package_add_json_filelist(struct pakfire* pakfire, - struct pakfire_file* file, void* data) { +static int __pakfire_package_add_json_filelist( + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct json_object* filelist = (struct json_object*)data; int r = 1; diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index 619d3f9ca..fe60feb5f 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -650,9 +650,9 @@ ERROR: return r; } -static int __pakfire_packager_add_files(struct pakfire* pakfire, - struct pakfire_file* file, void* p) { - struct pakfire_packager* packager = (struct pakfire_packager*)p; +static int __pakfire_packager_add_files( + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { + struct pakfire_packager* packager = data; return pakfire_packager_add_file(packager, file); } diff --git a/src/libpakfire/stripper.c b/src/libpakfire/stripper.c index cc73f5193..b86708586 100644 --- a/src/libpakfire/stripper.c +++ b/src/libpakfire/stripper.c @@ -108,7 +108,7 @@ struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* strippe } static int pakfire_stripper_find_elf( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_stripper* stripper = data; int r; @@ -159,7 +159,7 @@ static int pakfire_stripper_copy_source_file( } static int pakfire_stripper_copy_sources( - struct pakfire* pakfire, struct pakfire_file* file, void* data) { + struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_stripper* stripper = data; const char* filename = NULL; char basename[PATH_MAX]; @@ -184,8 +184,7 @@ static int pakfire_stripper_copy_sources( // Read DWARF information dwarf = dwarf_begin(fileno(f), DWARF_C_READ); if (!dwarf) { - CTX_ERROR(stripper->ctx, "Could not initialize DWARF context: %s\n", - dwarf_errmsg(-1)); + CTX_ERROR(ctx, "Could not initialize DWARF context: %s\n", dwarf_errmsg(-1)); r = -errno; goto ERROR; } @@ -204,8 +203,7 @@ static int pakfire_stripper_copy_sources( // Fetch the source files r = dwarf_getsrcfiles(die, &files, &count); if (r < 0) { - CTX_ERROR(stripper->ctx, "Could not fetch the source files: %s\n", - dwarf_errmsg(-1)); + CTX_ERROR(ctx, "Could not fetch the source files: %s\n", dwarf_errmsg(-1)); r = -errno; goto ERROR; } @@ -228,13 +226,12 @@ static int pakfire_stripper_copy_sources( if (pakfire_string_startswith(basename, "<") && pakfire_string_endswith(basename, ">")) continue; - CTX_DEBUG(stripper->ctx, "Found source file: %s\n", filename); + CTX_DEBUG(ctx, "Found source file: %s\n", filename); // Copy the file r = pakfire_stripper_copy_source_file(stripper, filename); if (r < 0) { - CTX_ERROR(stripper->ctx, "Could not copy source file %s: %s\n", - filename, strerror(-r)); + CTX_ERROR(ctx, "Could not copy source file %s: %s\n", filename, strerror(-r)); goto ERROR; } } -- 2.39.5