int pakfire_repo_cache_access(PakfireRepo repo, const char* path, int mode);
time_t pakfire_repo_cache_age(PakfireRepo repo, const char* path);
+// Scan
+
+int pakfire_repo_scan(PakfireRepo repo, int flags);
+
#ifdef PAKFIRE_PRIVATE
#include <solv/repo.h>
char** pakfire_split_string(const char* s, char delim);
void pakfire_partition_string(const char* s, const char* delim, char** s1, char** s2);
+#ifdef PAKFIRE_PRIVATE
+
+int pakfire_string_endswith(const char* s, const char* suffix);
+
+#endif
+
#endif /* PAKFIRE_UTIL_H */
pakfire_repo_read_solv;
pakfire_repo_read_solv_fp;
pakfire_repo_ref;
+ pakfire_repo_scan;
pakfire_repo_set_baseurl;
pakfire_repo_set_description;
pakfire_repo_set_enabled;
#############################################################################*/
#include <assert.h>
+#include <errno.h>
+#include <fts.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
return 0;
}
+static char* pakfire_repo_get_path(PakfireRepo repo) {
+ const char* baseurl = pakfire_repo_get_baseurl(repo);
+ if (!baseurl)
+ return NULL;
+
+ // Must be a local repository
+ if (!pakfire_string_startswith(baseurl, "dir://"))
+ return NULL;
+
+ return strdup(baseurl + strlen("dir://"));
+}
+
PAKFIRE_EXPORT const char* pakfire_repo_get_keyfile(PakfireRepo repo) {
return repo->appdata->keyfile;
}
return t;
}
+
+static int pakfire_repo_scan_file(PakfireRepo repo, const char* path) {
+ PakfireArchive archive = pakfire_archive_open(repo->pakfire, path);
+ if (!archive)
+ return errno;
+
+ // Import package into the repository
+ PakfirePackage pkg = pakfire_archive_make_package(archive, repo);
+ if (!pkg) {
+ pakfire_archive_unref(archive);
+ return errno;
+ }
+
+ pakfire_package_unref(pkg);
+ pakfire_archive_unref(archive);
+
+ return 0;
+}
+
+PAKFIRE_EXPORT int pakfire_repo_scan(PakfireRepo repo, int flags) {
+ char* path = pakfire_repo_get_path(repo);
+ if (!path)
+ return EINVAL;
+
+ int r = 1;
+
+ char* paths[] = {
+ path, NULL,
+ };
+
+ FTS* tree = fts_open(paths, FTS_NOCHDIR|FTS_NOSTAT, 0);
+ if (!tree)
+ return errno;
+
+ FTSENT* node;
+
+ while ((node = fts_read(tree))) {
+ // Skip anything that isn't a file
+ if (!(node->fts_info & FTS_F))
+ continue;
+
+ // Skip any files that do not end in "pfm"
+ if (!pakfire_string_endswith(node->fts_name, ".pfm"))
+ continue;
+
+ // Scan the file
+ r = pakfire_repo_scan_file(repo, node->fts_path);
+ if (r)
+ goto ERROR;
+ }
+
+ERROR:
+ fts_close(tree);
+ free(path);
+
+ return r;
+}
return !strncmp(s, prefix, strlen(prefix));
}
+int pakfire_string_endswith(const char* s, const char* suffix) {
+ return !strcmp(s + strlen(s) - strlen(suffix), suffix);
+}
+
char* pakfire_format_size(double size) {
char string[STRING_SIZE];
const char* units[] = {" ", "k", "M", "G", "T", NULL};
# #
#############################################################################*/
+#include <pakfire/repo.h>
+#include <pakfire/util.h>
+
#include "../testsuite.h"
+static int test_scan(const struct test* t) {
+ char baseurl[1024];
+ snprintf(baseurl, sizeof(baseurl) - 1, "dir://%s/data", TEST_SRC_PATH);
+
+ PakfireRepo repo = pakfire_repo_create(t->pakfire, "test");
+ ASSERT(repo);
+
+ pakfire_repo_set_baseurl(repo, baseurl);
+
+ int r = pakfire_repo_scan(repo, 0);
+ ASSERT(r == 0);
+
+ // There should be one package in this repository now
+ ASSERT(pakfire_repo_count(repo) == 1);
+
+ pakfire_repo_unref(repo);
+
+ return 0;
+}
+
int main(int argc, char** argv) {
+ testsuite_add_test(test_scan);
+
return testsuite_run();
}