#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>
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)
if (r)
goto ERROR;
+ // XXX Lint the package
+
ERROR:
if (packager)
pakfire_packager_unref(packager);
#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 */
# #
#############################################################################*/
-// 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;