]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Compile filelist first before scanning files
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 11:14:19 +0000 (11:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 11:14:19 +0000 (11:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c
src/libpakfire/include/pakfire/file.h
src/libpakfire/repo.c

index 87833249243b05c6d428dcc04f348f69be8ac785..5ff56b858fd646c94e00e9fe2c1638d9a72dcb9a 100644 (file)
@@ -179,6 +179,10 @@ PAKFIRE_EXPORT int pakfire_file_cmp(PakfireFile file1, PakfireFile file2) {
        return strcmp(path1, path2);
 }
 
+const char* pakfire_file_get_abspath(PakfireFile file) {
+       return file->abspath;
+}
+
 PAKFIRE_EXPORT const char* pakfire_file_get_path(PakfireFile file) {
        return file->path;
 }
index 6eeb9c6f25e0486bc802a4137811fd37b62d9d7e..e0e8045db0001b89da707cd2546bd06a5948d195 100644 (file)
@@ -73,6 +73,7 @@ PakfireFile pakfire_file_parse_from_file(const char* list, unsigned int format);
 struct archive_entry* pakfire_file_archive_entry(PakfireFile file);
 int pakfire_file_copy_archive_entry(PakfireFile file, struct archive_entry* entry);
 
+const char* pakfire_file_get_abspath(PakfireFile file);
 FILE* pakfire_file_fopen(PakfireFile file, const char* mode);
 
 #endif
index 9de5b3b3c66330ae518f2f0cefd93ef7719f35e9..7abf9b6230caa88b34c3cab871510659c9be4eba 100644 (file)
@@ -19,7 +19,6 @@
 #############################################################################*/
 
 #include <errno.h>
-#include <fts.h>
 #include <linux/limits.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -37,6 +36,8 @@
 #include <pakfire/constants.h>
 #include <pakfire/downloader.h>
 #include <pakfire/errno.h>
+#include <pakfire/file.h>
+#include <pakfire/filelist.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/pakfire.h>
@@ -739,6 +740,8 @@ PAKFIRE_EXPORT int pakfire_repo_clean(PakfireRepo repo) {
 }
 
 static int pakfire_repo_scan_file(PakfireRepo repo, const char* path) {
+       DEBUG(repo->pakfire, "Scanning %s...\n", path);
+
        PakfireArchive archive = pakfire_archive_open(repo->pakfire, path);
        if (!archive)
                return errno;
@@ -761,36 +764,45 @@ PAKFIRE_EXPORT int pakfire_repo_scan(PakfireRepo repo, int flags) {
        if (!path)
                return EINVAL;
 
-       int r = 1;
+       PakfireFilelist filelist;
+       int r = pakfire_filelist_create(&filelist, repo->pakfire);
+       if (r)
+               return r;
 
-       char* paths[] = {
-               path, NULL,
-       };
+       static const char* includes[] = { "*.pfm", NULL };
 
-       FTS* tree = fts_open(paths, FTS_NOCHDIR|FTS_NOSTAT, 0);
-       if (!tree)
-               return errno;
+       // Find all package files
+       r = pakfire_filelist_scan(filelist, path, includes, NULL);
+       if (r)
+               return r;
 
-       FTSENT* node;
+       // Fetch how many files have been found
+       const size_t num_files = pakfire_filelist_size(filelist);
 
-       while ((node = fts_read(tree))) {
-               // Skip anything that isn't a file
-               if (!(node->fts_info & FTS_F))
-                       continue;
+       for (unsigned int i = 0; i < num_files; i++) {
+               PakfireFile file = pakfire_filelist_get(filelist, i);
 
-               // Skip any files that do not end in "pfm"
-               if (!pakfire_string_endswith(node->fts_name, ".pfm"))
+               // Skip anything that isn't a regular file
+               int type = pakfire_file_get_type(file);
+               if (type != S_IFREG) {
+                       pakfire_file_unref(file);
                        continue;
+               }
+
+               const char* path = pakfire_file_get_abspath(file);
 
                // Scan the file
-               r = pakfire_repo_scan_file(repo, node->fts_path);
-               if (r)
+               r = pakfire_repo_scan_file(repo, path);
+               if (r) {
+                       pakfire_file_unref(file);
                        goto ERROR;
+               }
+
+               pakfire_file_unref(file);
        }
 
 ERROR:
-       fts_close(tree);
-       free(path);
+       pakfire_filelist_unref(filelist);
 
        return r;
 }