return r;
}
-static int pakfire_build_lint_package(
- struct pakfire_ctx* ctx, struct pakfire_package* pkg, void* data) {
- struct pakfire_archive* archive = NULL;
- int r;
-
- // Fetch the archive
- archive = pakfire_package_get_archive(pkg);
- if (!archive) {
- r = -errno;
- goto ERROR;
- }
-
- // Run the linter
- r = pakfire_archive_lint(archive, NULL, NULL);
- if (r < 0)
- goto ERROR;
-
-ERROR:
- if (archive)
- pakfire_archive_unref(archive);
-
- return r;
+static int pakfire_build_lint_archive(
+ struct pakfire_ctx* ctx, struct pakfire_archive* archive, void* data) {
+ return pakfire_archive_lint(archive, NULL, NULL);
}
static int pakfire_build_lint(struct pakfire_build* build) {
int r;
// Lint all packages
- r = pakfire_repo_walk_packages(build->repo,
- pakfire_build_lint_package, build, PAKFIRE_PACKAGELIST_KEEPGOING);
+ r = pakfire_repo_walk_archives(build->repo,
+ pakfire_build_lint_archive, build, PAKFIRE_PACKAGELIST_KEEPGOING);
if (r > 0)
ERROR(build->ctx, "Linting failed\n");
return r;
}
+
+typedef int (*pakfire_repo_walk_archives_callback)
+ (struct pakfire_ctx* ctx, struct pakfire_archive* archive, void* data);
+
+struct pakfire_repo_walk_archives_state {
+ pakfire_repo_walk_archives_callback callback;
+ void* data;
+};
+
+static int __pakfire_repo_walk_archives(
+ struct pakfire_ctx* ctx, struct pakfire_package* pkg, void* data) {
+ const struct pakfire_repo_walk_archives_state* state = data;
+ struct pakfire_archive* archive = NULL;
+ int r;
+
+ // Check if we actually have a callback
+ if (!state->callback)
+ return -EINVAL;
+
+ // Fetch the archive
+ archive = pakfire_package_get_archive(pkg);
+ if (!archive)
+ return -errno;
+
+ // Call the callback
+ r = state->callback(ctx, archive, state->data);
+
+ // Cleanup
+ pakfire_archive_unref(archive);
+
+ return r;
+}
+
+int pakfire_repo_walk_archives(struct pakfire_repo* self,
+ int (*callback)(struct pakfire_ctx* ctx, struct pakfire_archive* archive, void* data), void* data, int flags) {
+ struct pakfire_packagelist* list = NULL;
+ int r;
+
+ struct pakfire_repo_walk_archives_state state = {
+ .callback = callback,
+ .data = data,
+ };
+
+ // This only works on local repositories
+ if (!pakfire_repo_is_local(self))
+ return -ENOTSUP;
+
+ // Create a new packagelist
+ r = pakfire_packagelist_create(&list, self->ctx);
+ if (r < 0)
+ goto ERROR;
+
+ // Import all packages
+ r = pakfire_repo_to_packagelist(self, list);
+ if (r < 0)
+ goto ERROR;
+
+ // Iterate over all packages
+ r = pakfire_packagelist_walk(list, __pakfire_repo_walk_archives, &state, flags);
+ if (r < 0)
+ goto ERROR;
+
+ERROR:
+ if (list)
+ pakfire_packagelist_unref(list);
+
+ return r;
+}
int pakfire_repo_walk_packages(struct pakfire_repo* self,
int (*callback)(struct pakfire_ctx* ctx, struct pakfire_package* pkg, void* data), void* data, int flags);
+int pakfire_repo_walk_archives(struct pakfire_repo* self,
+ int (*callback)(struct pakfire_ctx* ctx, struct pakfire_archive* archive, void* data), void* data, int flags);
#endif /* PAKFIRE_REPO_H */