]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Reuse function to walk through the package filelist
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Mar 2023 14:10:14 +0000 (14:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Mar 2023 14:10:14 +0000 (14:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 956d486d828a486372c0a13e8761082ad309ab72..7b05b7b67fa7cd56884b9b0aeeb5136391695f63 100644 (file)
@@ -992,13 +992,19 @@ ERROR:
        return r;
 }
 
+enum {
+       PAKFIRE_BUILD_CLEANUP_FILES         = (1 << 0),
+       PAKFIRE_BUILD_ERROR_IF_NOT_EMPTY    = (1 << 1),
+};
+
 /*
        This helper function takes a callback which is expected to add any files
-       to the given filelist which will be all removed after.
+       to the given filelist which will optionally be all removed after.
 */
-static int pakfire_build_post_remove_files(struct pakfire_build* build,
+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 (*callback)(struct pakfire* pakfire, struct pakfire_file* file, void* data),
+               int flags) {
        struct pakfire_filelist* removees = NULL;
        int r;
 
@@ -1020,14 +1026,20 @@ static int pakfire_build_post_remove_files(struct pakfire_build* build,
                pakfire_filelist_dump(removees, 0);
 
                // Remove all files on the removee list
-               r = pakfire_filelist_cleanup(removees);
-               if (r)
-                       goto ERROR;
+               if (flags & PAKFIRE_BUILD_CLEANUP_FILES) {
+                       r = pakfire_filelist_cleanup(removees);
+                       if (r)
+                               goto ERROR;
 
-               // Remove all files from the filelist
-               r = pakfire_filelist_remove_all(filelist, removees);
-               if (r)
-                       goto ERROR;
+                       // Remove all files from the filelist
+                       r = pakfire_filelist_remove_all(filelist, removees);
+                       if (r)
+                               goto ERROR;
+               }
+
+               // Report an error if any files have been found
+               if (flags & PAKFIRE_BUILD_ERROR_IF_NOT_EMPTY)
+                       r = 1;
        }
 
 ERROR:
@@ -1065,8 +1077,10 @@ static int __pakfire_build_remove_static_libraries(
 
 static int pakfire_build_post_remove_static_libraries(
                struct pakfire_build* build, struct pakfire_filelist* filelist) {
-       return pakfire_build_post_remove_files(build, filelist,
-               "Removing static libaries...", __pakfire_build_remove_static_libraries);
+       return pakfire_build_post_process_files(build, filelist,
+               "Removing static libaries...",
+               __pakfire_build_remove_static_libraries,
+               PAKFIRE_BUILD_CLEANUP_FILES);
 }
 
 static int __pakfire_build_remove_libtool_archives(
@@ -1082,8 +1096,10 @@ static int __pakfire_build_remove_libtool_archives(
 
 static int pakfire_build_post_remove_libtool_archives(
                struct pakfire_build* build, struct pakfire_filelist* filelist) {
-       return pakfire_build_post_remove_files(build, filelist,
-               "Removing libtool archives...", __pakfire_build_remove_libtool_archives);
+       return pakfire_build_post_process_files(build, filelist,
+               "Removing libtool archives...",
+               __pakfire_build_remove_libtool_archives,
+               PAKFIRE_BUILD_CLEANUP_FILES);
 }
 
 static int __pakfire_build_check_broken_symlinks(
@@ -1112,34 +1128,12 @@ static int __pakfire_build_check_broken_symlinks(
 
 static int pakfire_build_post_check_broken_symlinks(
                struct pakfire_build* build, struct pakfire_filelist* filelist) {
-       struct pakfire_filelist* broken = NULL;
-       int r;
-
-       // Create a new filelist
-       r = pakfire_filelist_create(&broken, build->pakfire);
-       if (r)
-               goto ERROR;
-
-       // Find any broken symlinks
-       r = pakfire_filelist_walk(filelist, __pakfire_build_check_broken_symlinks, broken);
-       if (r)
-               goto ERROR;
-
-       if (!pakfire_filelist_is_empty(broken)) {
-               INFO(build->pakfire, "Broken symlinks have been found:\n");
-
-               // Show all files
-               pakfire_filelist_dump(broken, 0);
-
-               // Check failed
-               r = 1;
-       }
-
-ERROR:
-       if (broken)
-               pakfire_filelist_unref(broken);
+       return pakfire_build_post_process_files(build, filelist,
+               "Broken symlinks have been found:",
+               __pakfire_build_check_broken_symlinks,
+               PAKFIRE_BUILD_ERROR_IF_NOT_EMPTY);
+}
 
-       return r;
 }
 
 static int pakfire_build_run_post_build_checks(struct pakfire_build* build) {