aboutsummaryrefslogtreecommitdiff
path: root/src/repo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo.c')
-rw-r--r--src/repo.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/repo.c b/src/repo.c
index e69de29..9238a27 100644
--- a/src/repo.c
+++ b/src/repo.c
@@ -0,0 +1,56 @@
+#define _XOPEN_SOURCE 700
+
+#include "repo.h"
+
+#include "dirent.h"
+#include "limits.h"
+#include "malloc.h"
+#include "stdio.h"
+
+int repo_check_package(pow_repo **repos, size_t repo_count, const char *query) {
+ if (!repos) {
+ printf("no repos defined in your config, please define them\n");
+
+ return 1;
+ }
+
+ DIR *dp;
+ struct dirent *ep;
+
+ for (size_t i = 0; i < repo_count; i++) {
+ char *package_path = malloc(PATH_MAX);
+
+ if (!package_path) {
+ printf("failed to allocate package_path, sizeof %zu\n", PATH_MAX);
+
+ return 1;
+ }
+
+ int written =
+ snprintf(package_path, PATH_MAX, "%s/%s", repos[i]->path, query);
+
+ if (written >= PATH_MAX) {
+ printf("something went seriously wrong. the path for the package %s is "
+ "too long?\n",
+ query);
+
+ free(package_path);
+
+ return 1;
+ }
+
+ dp = opendir(package_path);
+
+ free(package_path);
+
+ if (!dp) {
+ continue;
+ }
+
+ printf("found package %s in repo %s\n", query, repos[i]->path);
+
+ closedir(dp);
+ }
+
+ return 0;
+}