From 5a233c5c78a81c15991db4b7de02b7141e3f1624 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 21 Nov 2022 15:49:05 +0000 Subject: [PATCH] dist: Pass absolute path when searching for files Signed-off-by: Michael Tremer --- src/libpakfire/dist.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 1d249bef1..a5a9feaf2 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -330,17 +330,31 @@ ERROR: return r; } -static int pakfire_dist_add_files(struct pakfire* pakfire, struct pakfire_packager* packager, - const char* path) { +static const char* pakfire_dist_find_root(struct pakfire* pakfire, const char* file) { + char path[PATH_MAX]; + + // Find the absolute path of the makefile + char* p = realpath(file, path); + if (!p) { + ERROR(pakfire, "realpath(%s) failed: %m\n", file); + return NULL; + } + + // Return the parent directory + return pakfire_dirname(p); +} + +static int pakfire_dist_add_files(struct pakfire* pakfire, + struct pakfire_packager* packager, const char* file) { struct pakfire_filelist* filelist = NULL; int r = 1; - // Find the parent directory - const char* dirname = pakfire_dirname(path); - if (!dirname) + // Find the package directory + const char* root = pakfire_dist_find_root(pakfire, file); + if (!root) return 1; - DEBUG(pakfire, "Adding all files in '%s' to package...\n", dirname); + DEBUG(pakfire, "Adding all files in '%s' to package...\n", root); // Create a new filelist r = pakfire_filelist_create(&filelist, pakfire); @@ -348,7 +362,7 @@ static int pakfire_dist_add_files(struct pakfire* pakfire, struct pakfire_packag goto ERROR; // Scan for any files - r = pakfire_filelist_scan(filelist, dirname, NULL, pakfire_dist_excludes); + r = pakfire_filelist_scan(filelist, root, NULL, pakfire_dist_excludes); if (r) goto ERROR; -- 2.39.5