]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Pass absolute path when searching for files
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Nov 2022 15:49:05 +0000 (15:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Nov 2022 15:49:05 +0000 (15:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c

index 1d249bef14e8261419678940044d6412faea387b..a5a9feaf247745cc0c96919e6231c60afec80879 100644 (file)
@@ -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;