]> git.ipfire.org Git - pakfire.git/commitdiff
linter: Refactor
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 18:50:24 +0000 (18:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 18:50:24 +0000 (18:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c
src/libpakfire/include/pakfire/linter.h
src/libpakfire/linter.c

index 4d14077784b8282804c9f75872b3bb7f65cdda25..d23f8602c494e7c5a24e2a5c6e8a224c264e7b32 100644 (file)
@@ -31,7 +31,6 @@
 #include <pakfire/arch.h>
 #include <pakfire/dist.h>
 #include <pakfire/i18n.h>
-#include <pakfire/linter.h>
 #include <pakfire/logging.h>
 #include <pakfire/mirror.h>
 #include <pakfire/mirrorlist.h>
@@ -480,11 +479,6 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
        if (r)
                goto ERROR;
 
-       // Perform some linting
-       r = pakfire_lint_makefile(pakfire, makefile, path, pkg);
-       if (r)
-               goto ERROR;
-
        // Create a packager
        r = pakfire_packager_create(&packager, pakfire, pkg);
        if (r)
@@ -505,6 +499,8 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
        if (r)
                goto ERROR;
 
+       // XXX Lint the package
+
 ERROR:
        if (packager)
                pakfire_packager_unref(packager);
index 3c3626a9766d50715a6884ef849f94c6f7b95892..abe09f97c0bb78517a49326398055c92e84d43c1 100644 (file)
 #ifndef PAKFIRE_LINTER_H
 #define PAKFIRE_LINTER_H
 
+#include <pakfire/ctx.h>
 #include <pakfire/package.h>
-#include <pakfire/pakfire.h>
-#include <pakfire/parser.h>
 
-int pakfire_lint_makefile(struct pakfire* pakfire, struct pakfire_parser* makefile,
-       const char* path, struct pakfire_package* pkg);
+struct pakfire_linter;
+
+int pakfire_linter_create(struct pakfire_linter** linter,
+       struct pakfire_ctx* ctx, struct pakfire_package* pkg);
+
+struct pakfire_linter* pakfire_linter_ref(struct pakfire_linter* linter);
+struct pakfire_linter* pakfire_linter_unref(struct pakfire_linter* linter);
+
+int pakfire_linter_lint(struct pakfire_linter* linter);
 
 #endif /* PAKFIRE_LINTER_H */
index 5b6608f4119f7c5d259f7cc949e839e640b6de09..0b2d37f40b2a386f716eab583ccff34dc55461cf 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
+#include <errno.h>
+#include <stdlib.h>
 
 #include <pakfire/linter.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
-#include <pakfire/pakfire.h>
-#include <pakfire/parser.h>
-#include <pakfire/path.h>
-#include <pakfire/string.h>
-#include <pakfire/util.h>
-
-static int pakfire_lint_makefile_name(struct pakfire* pakfire,
-               const char* path, struct pakfire_package* pkg) {
-       char basename[PATH_MAX];
-       int r;
 
-       // Fetch the package name
-       const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME);
+struct pakfire_linter {
+       struct pakfire_ctx* ctx;
+       int nrefs;
 
-       // Check if the makefile ended on .nm
-       if (!pakfire_string_endswith(path, ".nm")) {
-               ERROR(pakfire, "Invalid extension for makefile: %s\n", path);
-               return 1;
-       }
+       // Package
+       struct pakfire_package* pkg;
+};
 
-       // Determine the basename of the file
-       r = pakfire_path_basename(basename, path);
-       if (r)
-               return r;
+static void pakfire_linter_free(struct pakfire_linter* linter) {
+       if (linter->pkg)
+               pakfire_package_unref(linter->pkg);
+       if (linter->ctx)
+               pakfire_ctx_unref(linter->ctx);
+       free(linter);
+}
 
-       // Remove the file extension
-       r = pakfire_path_strip_extension(basename);
-       if (r) {
-               ERROR(pakfire, "Could not strip extension from makefile: %m\n");
-               return r;
-       }
+int pakfire_linter_create(struct pakfire_linter** linter,
+               struct pakfire_ctx* ctx, struct pakfire_package* pkg) {
+       struct pakfire_linter* l = NULL;
+
+       // Allocate a new object
+       l = calloc(1, sizeof(*l));
+       if (!l)
+               return -errno;
+
+       // Reference the context
+       l->ctx = pakfire_ctx_ref(ctx);
+
+       // Initialize reference counter
+       l->nrefs = 1;
+
+       // Store the package
+       l->pkg = pakfire_package_ref(pkg);
+
+       // Return the pointer
+       *linter = l;
+
+       return 0;
+}
+
+struct pakfire_linter* pakfire_linter_ref(struct pakfire_linter* linter) {
+       ++linter->nrefs;
+
+       return linter;
+}
+
+struct pakfire_linter* pakfire_linter_unref(struct pakfire_linter* linter) {
+       if (--linter->nrefs > 0)
+               return linter;
+
+       pakfire_linter_free(linter);
+       return NULL;
+}
+
+static int pakfire_linter_name(struct pakfire_linter* linter) {
+       int r;
+
+       // Fetch the package name
+       const char* name = pakfire_package_get_string(linter->pkg, PAKFIRE_PKG_NAME);
 
-       // Check if the package name matches
-       if (strcmp(basename, name) != 0) {
-               ERROR(pakfire, "%s: Makefile has a different package name (%s)\n",
-                       path, name);
-               return 1;
-       }
+       // XXX Do something here...
 
        return 0;
 }
 
-int pakfire_lint_makefile(struct pakfire* pakfire, struct pakfire_parser* makefile,
-               const char* path, struct pakfire_package* pkg) {
+int pakfire_linter_lint(struct pakfire_linter* linter) {
        int r;
 
-       // Check makefile name
-       r = pakfire_lint_makefile_name(pakfire, path, pkg);
-       if (r)
+       // Lint the name
+       r = pakfire_linter_name(linter);
+       if (r < 0)
                return r;
 
        return 0;