]> git.ipfire.org Git - pakfire.git/commitdiff
build: Implement symlink dependencies
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Jan 2025 13:56:19 +0000 (13:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Jan 2025 13:56:19 +0000 (13:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c

index 798149aefe388d39acbad3993fcb11ac8a7c856b..8a3c659b60597b5e0d4b6725de6542b868e55b21 100644 (file)
@@ -710,6 +710,36 @@ static int pakfire_build_find_python_abi_requires(
                PAKFIRE_PKG_REQUIRES, "python-abi = %s", basename + strlen("python"));
 }
 
+static int pakfire_build_find_symlink_destinations(
+               struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
+       const char* symlink = NULL;
+       const char* path = NULL;
+       char buffer[PATH_MAX];
+       int r;
+
+       // Fetch the path
+       path = pakfire_file_get_path(file);
+       if (!path)
+               return -EINVAL;
+
+       // Fetch the destination
+       symlink = pakfire_file_get_symlink(file);
+       if (!symlink)
+               return -EINVAL;
+
+       // Resolve the symlink
+       r = pakfire_path_merge(buffer, path, symlink);
+       if (r < 0)
+               return r;
+
+       // Ignore if the destination is also part of this package
+       if (pakfire_filelist_contains(deps->filelist, buffer))
+               return 0;
+
+       // Otherwise add it as dependency
+       return pakfire_package_add_dep(deps->pkg, PAKFIRE_PKG_REQUIRES, "%s", buffer);
+}
+
 static int pakfire_build_find_provides(
                struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) {
        struct pakfire_find_deps_ctx* deps = data;
@@ -776,7 +806,13 @@ static int pakfire_build_find_requires(
                                if (r < 0)
                                        return r;
                        }
+                       break;
 
+               // Symlinks
+               case S_IFLNK:
+                       r = pakfire_build_find_symlink_destinations(ctx, file, deps);
+                       if (r < 0)
+                               return r;
                        break;
        }
 
@@ -834,8 +870,9 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
        int r;
 
        struct pakfire_find_deps_ctx deps = {
-               .build = build,
-               .pkg   = pkg,
+               .build    = build,
+               .pkg      = pkg,
+               .filelist = filelist,
        };
 
        // Fetch the provides filter