#############################################################################*/
#include <errno.h>
-#include <fts.h>
#include <linux/limits.h>
#include <stdint.h>
#include <stdio.h>
#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>
}
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;
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;
}