PyObject* PyExc_CheckError;
PyObject* PyExc_CheckFileVerificationError;
+struct pakfire_ctx* pakfire_ctx = NULL;
+
+static int initialize_context(void) {
+ int r;
+
+ // Create a new context
+ r = pakfire_ctx_create(&pakfire_ctx);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto ERROR;
+ }
+
+ERROR:
+ if (pakfire_ctx)
+ pakfire_ctx_unref(pakfire_ctx);
+
+ return r;
+}
+
static PyObject* _pakfire_native_arch(void) {
const char* arch = pakfire_arch_native();
if (!arch)
};
PyMODINIT_FUNC PyInit__pakfire(void) {
+ int r;
+
/* Initialize locale */
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE_TARNAME, "/usr/share/locale");
if (PyModule_AddIntMacro(module, PAKFIRE_KEY_ALGO_ED25519) < 0)
goto ERROR;
+ // Initialize the context
+ r = initialize_context();
+ if (r)
+ goto ERROR;
+
return module;
ERROR:
#include <pakfire/archive.h>
#include <pakfire/build.h>
#include <pakfire/constants.h>
+#include <pakfire/ctx.h>
#include <pakfire/dist.h>
#include <pakfire/jail.h>
#include <pakfire/logging.h>
#include "repo.h"
#include "util.h"
+extern struct pakfire_ctx* pakfire_ctx;
+
static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
PakfireObject* self = (PakfireObject *)type->tp_alloc(type, 0);
if (self) {
Py_BEGIN_ALLOW_THREADS
// Create a new Pakfire instance
- r = pakfire_create(&self->pakfire, path, arch, fconf, flags,
+ r = pakfire_create(&self->pakfire, pakfire_ctx, path, arch, fconf, flags,
Pakfire_log_callback, self->callbacks.log);
Py_END_ALLOW_THREADS
}
int cli_setup_pakfire(struct pakfire** pakfire, struct cli_config* config) {
+ struct pakfire_ctx* ctx = NULL;
struct pakfire* p = NULL;
FILE* f = NULL;
int r;
}
}
+ // Create a new context
+ r = pakfire_ctx_create(&ctx);
+ if (r)
+ goto ERROR;
+
// Initialize Pakfire
- r = pakfire_create(&p, config->root, config->arch, f, config->flags, NULL, NULL);
+ r = pakfire_create(&p, ctx, config->root, config->arch, f, config->flags, NULL, NULL);
if (r)
goto ERROR;
*pakfire = p;
ERROR:
+ if (ctx)
+ pakfire_ctx_unref(ctx);
if (f)
fclose(f);
struct pakfire;
+#include <pakfire/ctx.h>
#include <pakfire/filelist.h>
#include <pakfire/key.h>
#include <pakfire/packagelist.h>
typedef void (*pakfire_status_callback)(struct pakfire* pakfire, void* data,
int progress, const char* status);
-int pakfire_create(struct pakfire** pakfire, const char* path, const char* arch,
- FILE* conf, int flags, pakfire_log_callback log_callback, void* log_data);
+int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
+ const char* path, const char* arch, FILE* conf, int flags,
+ pakfire_log_callback log_callback, void* log_data);
struct pakfire* pakfire_ref(struct pakfire* pakfire);
struct pakfire* pakfire_unref(struct pakfire* pakfire);
#include <pakfire/build.h>
#include <pakfire/config.h>
#include <pakfire/constants.h>
+#include <pakfire/ctx.h>
#include <pakfire/db.h>
#include <pakfire/dependencies.h>
#include <pakfire/dist.h>
#define LOCK_PATH PAKFIRE_PRIVATE_DIR "/.lock"
struct pakfire {
+ struct pakfire_ctx* ctx;
int nrefs;
char path[PATH_MAX];
if (pakfire->config)
pakfire_config_unref(pakfire->config);
+ if (pakfire->ctx)
+ pakfire_ctx_unref(pakfire->ctx);
+
free(pakfire);
}
return r;
}
-PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
- const char* arch, FILE* conf, int flags, pakfire_log_callback log_callback, void* log_data) {
+PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
+ const char* path, const char* arch, FILE* conf, int flags,
+ pakfire_log_callback log_callback, void* log_data) {
char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
char private_dir[PATH_MAX];
const char* env = NULL;
if (!p)
return -errno;
+ // Reference the context
+ p->ctx = pakfire_ctx_ref(ctx);
+
p->nrefs = 1;
p->flags = flags;
#include <pakfire/util.h>
int main(int argc, const char* argv[]) {
+ struct pakfire_ctx* ctx = NULL;
struct pakfire* pakfire = NULL;
struct pakfire_parser* parser = NULL;
struct pakfire_parser_error* error = NULL;
goto ERROR;
}
+ // Create a new context
+ r = pakfire_ctx_create(&ctx);
+ if (r)
+ goto ERROR;
+
// Create a pakfire instance
- r = pakfire_create(&pakfire, root, NULL, NULL,
+ r = pakfire_create(&pakfire, ctx, root, NULL, NULL,
PAKFIRE_FLAGS_DEBUG, pakfire_log_stderr, NULL);
if (r) {
fprintf(stderr, "Could not create Pakfire: %m\n");
pakfire_parser_unref(parser);
if (pakfire)
pakfire_unref(pakfire);
+ if (ctx)
+ pakfire_ctx_unref(ctx);
return r;
}
struct testsuite ts;
static int test_run(int i, struct test* t) {
+ struct pakfire_ctx* ctx = NULL;
struct pakfire* p = NULL;
FILE* c = NULL;
const int flags = PAKFIRE_FLAGS_DEBUG;
LOG("running %s (%s)\n", t->name, root);
+ // Create a new context
+ r = pakfire_ctx_create(&ctx);
+ if (r) {
+ LOG("Could not create context: %m\n");
+ goto ERROR;
+ }
+
// Open the configuration file
c = fopen(TEST_SRC_PATH "/pakfire.conf", "r");
if (!c) {
}
// Create a pakfire instance
- r = pakfire_create(&t->pakfire, root, NULL, c, flags, pakfire_log_stderr, NULL);
+ r = pakfire_create(&t->pakfire, ctx, root, NULL, c, flags, pakfire_log_stderr, NULL);
if (r) {
LOG("ERROR: Could not initialize pakfire: %m\n");
goto ERROR;
t->pakfire = NULL;
}
+ if (ctx)
+ pakfire_ctx_unref(ctx);
+
// Close the configuration file
if (c)
fclose(c);