From: Michael Tremer Date: Tue, 9 Mar 2021 23:51:49 +0000 (+0000) Subject: dist: Add all files in the source directory X-Git-Tag: 0.9.28~1285^2~582 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49b1f379fb69b3335fc5cd6f9045be71aabfda48;p=pakfire.git dist: Add all files in the source directory Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 7e097bb3b..0059aec23 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include #include @@ -33,6 +34,63 @@ #include #include #include +#include + +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;