]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Add all files in the source directory
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Mar 2021 23:51:49 +0000 (23:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Mar 2021 23:51:49 +0000 (23:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c

index 7e097bb3b5718d92822f43f2890796ec6e00c449..0059aec234fcbd4d84a554fd94ec6aa5ee3008fe 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <errno.h>
+#include <fts.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <stddef.h>
 #include <pakfire/private.h>
 #include <pakfire/repo.h>
 #include <pakfire/types.h>
+#include <pakfire/util.h>
+
+static int pakfire_dist_add_files(Pakfire pakfire, struct pakfire_packager* packager,
+               const char* path) {
+       int r = 1;
+
+       // Find the parent directory
+       char* dirname = pakfire_dirname(path);
+       if (!dirname)
+               return 1;
+
+       DEBUG(pakfire, "Adding all files in '%s' to package...\n", dirname);
+
+       char* paths[2] = {
+               dirname, NULL,
+       };
+
+       FTS* f = fts_open(paths, FTS_NOCHDIR|FTS_NOSTAT, NULL);
+       if (!f)
+               goto ERROR;
+
+       for (;;) {
+               FTSENT* fent = fts_read(f);
+               if (!fent)
+                       break;
+
+               // Only handle files
+               if (fent->fts_info & FTS_F) {
+                       const char* filename = pakfire_path_relpath(dirname, fent->fts_path);
+                       if (filename)
+                               filename++;
+
+                       DEBUG(pakfire, "Adding '%s' to package...\n", filename);
+
+                       r = pakfire_packager_add(packager, fent->fts_path, filename);
+                       if (r)
+                               goto ERROR;
+               }
+       }
+
+       // If fts_read() encountered an error, errno will be set
+       if (errno) {
+               r = 1;
+               goto ERROR;
+       }
+
+       // Success
+       r = 0;
+
+ERROR:
+       if (f)
+               fts_close(f);
+
+       free(dirname);
+
+       return r;
+}
 
 PAKFIRE_EXPORT int pakfire_dist(Pakfire pakfire, const char* path, const char* target) {
        PakfireParser makefile;
@@ -76,8 +134,8 @@ PAKFIRE_EXPORT int pakfire_dist(Pakfire pakfire, const char* path, const char* t
        if (r)
                goto ERROR;
 
-       // Add the makefile
-       r = pakfire_packager_add(packager, path, NULL);
+       // Add all files in the directory
+       r = pakfire_dist_add_files(pakfire, packager, path);
        if (r)
                goto ERROR;