#############################################################################*/
#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;
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;