#include <stddef.h>
#include <stdlib.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
#include <pakfire/arch.h>
#include <pakfire/dist.h>
#include <pakfire/i18n.h>
const char* path, struct pakfire_parser_error** error) {
int r = 1;
+ // Fetch context
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
*parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
if (!*parser) {
r = 1;
// Find all macros
- DEBUG(pakfire, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN);
+ CTX_DEBUG(ctx, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN);
glob_t globmacros;
r = glob(PAKFIRE_MACROS_GLOB_PATTERN, 0, NULL, &globmacros);
goto ERROR;
default:
- ERROR(pakfire, "glob() returned an unhandled error: %d\n", r);
+ CTX_ERROR(ctx, "glob() returned an unhandled error: %d\n", r);
goto ERROR;
}
- DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc);
+ CTX_DEBUG(ctx, "Found %zu macro(s)\n", globmacros.gl_pathc);
// Read all macros
for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
// Finally, parse the makefile
r = pakfire_parser_read_file(*parser, path, error);
if (r) {
- ERROR(pakfire, "Could not read makefile %s: %m\n", path);
+ CTX_ERROR(ctx, "Could not read makefile %s: %m\n", path);
goto ERROR;
}
*parser = NULL;
}
+ if (ctx)
+ pakfire_ctx_unref(ctx);
+
return r;
}
-static int pakfire_dist_get_mirrorlist(struct pakfire* pakfire,
+static int pakfire_dist_get_mirrorlist(struct pakfire_ctx* ctx, struct pakfire* pakfire,
struct pakfire_parser* makefile, struct pakfire_mirrorlist** list) {
- struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
struct pakfire_mirrorlist* m = NULL;
struct pakfire_mirror* mirror = NULL;
char* p = NULL;
// Create mirrorlist
r = pakfire_mirrorlist_create(&m, ctx);
if (r) {
- ERROR(pakfire, "Could not create the mirrorlist\n");
+ CTX_ERROR(ctx, "Could not create the mirrorlist\n");
goto ERROR;
}
ERROR:
if (m)
pakfire_mirrorlist_unref(m);
- if (ctx)
- pakfire_ctx_unref(ctx);
if (source_dl)
free(source_dl);
return pakfire_packager_add(packager, cache_path, archive_path);
}
-static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_packager* packager,
- struct pakfire_package* pkg, struct pakfire_parser* makefile) {
+static int pakfire_dist_add_sources(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+ struct pakfire_packager* packager, struct pakfire_package* pkg, struct pakfire_parser* makefile) {
struct pakfire_mirrorlist* mirrorlist = NULL;
char* sources = NULL;
char* p = NULL;
if (!sources)
return 0;
- struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
-
// Fetch the mirrorlist
- r = pakfire_dist_get_mirrorlist(pakfire, makefile, &mirrorlist);
+ r = pakfire_dist_get_mirrorlist(ctx, pakfire, makefile, &mirrorlist);
if (r)
goto ERROR;
// Add all mirrors
const char* source = strtok_r(sources, " ", &p);
while (source) {
- DEBUG(pakfire, "Adding source file %s\n", source);
+ CTX_DEBUG(ctx, "Adding source file %s\n", source);
r = pakfire_dist_add_source(pakfire, packager, pkg, ctx, mirrorlist, source);
if (r) {
- ERROR(pakfire, "Could not add '%s' to package: %m\n", source);
+ CTX_ERROR(ctx, "Could not add '%s' to package: %m\n", source);
goto ERROR;
}
ERROR:
if (mirrorlist)
pakfire_mirrorlist_unref(mirrorlist);
- if (ctx)
- pakfire_ctx_unref(ctx);
if (sources)
free(sources);
return __pakfire_path_dirname(root, length, p);
}
-static int pakfire_dist_add_files(struct pakfire* pakfire,
+static int pakfire_dist_add_files(struct pakfire_ctx* ctx, struct pakfire* pakfire,
struct pakfire_packager* packager, const char* file) {
struct pakfire_filelist* filelist = NULL;
char root[PATH_MAX];
// Find the package directory
r = pakfire_dist_find_root(root, file);
if (r) {
- ERROR(pakfire, "Could not find package root directory: %s\n", strerror(r));
+ CTX_ERROR(ctx, "Could not find package root directory: %s\n", strerror(r));
return r;
}
- DEBUG(pakfire, "Adding all files in '%s' to package...\n", root);
+ CTX_DEBUG(ctx, "Adding all files in '%s' to package...\n", root);
// Create a new filelist
r = pakfire_filelist_create(&filelist, pakfire);
struct pakfire_packager* packager = NULL;
struct pakfire_package* pkg = NULL;
+ // Fetch context
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
// Load makefile
int r = pakfire_read_makefile(&makefile, pakfire, path, &error);
if (r) {
if (error)
pakfire_parser_error_unref(error);
else
- ERROR(pakfire, "Could not read makefile: %m\n");
+ CTX_ERROR(ctx, "Could not read makefile: %m\n");
- return r;
+ goto ERROR;
}
// The architecture is always "src"
r = pakfire_parser_set(makefile, NULL, "arch", "src", 0);
if (r) {
- ERROR(pakfire, "Could not set architecture to 'src': %m\n");
+ CTX_ERROR(ctx, "Could not set architecture to 'src': %m\n");
goto ERROR;
}
goto ERROR;
// Add all files in the directory
- r = pakfire_dist_add_files(pakfire, packager, path);
+ r = pakfire_dist_add_files(ctx, pakfire, packager, path);
if (r)
goto ERROR;
// Add all source files (which might need to be downloaded)
- r = pakfire_dist_add_sources(pakfire, packager, pkg, makefile);
+ r = pakfire_dist_add_sources(ctx, pakfire, packager, pkg, makefile);
if (r)
goto ERROR;
pakfire_packager_unref(packager);
if (pkg)
pakfire_package_unref(pkg);
- pakfire_parser_unref(makefile);
+ if (makefile)
+ pakfire_parser_unref(makefile);
return r;
}