From: Michael Tremer Date: Tue, 6 Apr 2021 11:14:19 +0000 (+0000) Subject: repo: Compile filelist first before scanning files X-Git-Tag: 0.9.28~1285^2~441 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4c2f7a9c2d42e19a80b242811704c1a3beee904;p=pakfire.git repo: Compile filelist first before scanning files Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 878332492..5ff56b858 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -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; } diff --git a/src/libpakfire/include/pakfire/file.h b/src/libpakfire/include/pakfire/file.h index 6eeb9c6f2..e0e8045db 100644 --- a/src/libpakfire/include/pakfire/file.h +++ b/src/libpakfire/include/pakfire/file.h @@ -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 diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 9de5b3b3c..7abf9b623 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -19,7 +19,6 @@ #############################################################################*/ #include -#include #include #include #include @@ -37,6 +36,8 @@ #include #include #include +#include +#include #include #include #include @@ -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; }