]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Use filelist to scan for any source files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Aug 2022 08:38:30 +0000 (08:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Aug 2022 08:38:30 +0000 (08:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c

index 9f06ffedf2f5819aa02bcdf860e4864f74e67be1..49eb06e9d5a8187801fe50662991e25f0341f436 100644 (file)
@@ -320,6 +320,7 @@ ERROR:
 
 static int pakfire_dist_add_files(struct pakfire* pakfire, struct pakfire_packager* packager,
                const char* path) {
+       struct pakfire_filelist* filelist = NULL;
        int r = 1;
 
        // Find the parent directory
@@ -329,45 +330,24 @@ static int pakfire_dist_add_files(struct pakfire* pakfire, struct pakfire_packag
 
        DEBUG(pakfire, "Adding all files in '%s' to package...\n", dirname);
 
-       char* paths[2] = {
-               (char*)dirname, NULL,
-       };
-
-       FTS* f = fts_open(paths, FTS_NOCHDIR|FTS_NOSTAT, NULL);
-       if (!f)
+       // Create a new filelist
+       r = pakfire_filelist_create(&filelist, pakfire);
+       if (r)
                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;
+       // Scan for any files
+       r = pakfire_filelist_scan(filelist, dirname, NULL, NULL);
+       if (r)
                goto ERROR;
-       }
 
-       // Success
-       r = 0;
+       // Add all files to the package
+       r = pakfire_packager_add_files(packager, filelist, 0);
+       if (r)
+               goto ERROR;
 
 ERROR:
-       if (f)
-               fts_close(f);
+       if (filelist)
+               pakfire_filelist_unref(filelist);
 
        return r;
 }