#include <errno.h>
#include <limits.h>
+#include <pakfire/config.h>
#include <pakfire/pakfire.h>
#include <pakfire/repo.h>
}
int cli_setup_pakfire(struct pakfire** pakfire, struct cli_config* config) {
+ struct pakfire_config* c = NULL;
struct pakfire* p = NULL;
FILE* f = NULL;
int r;
+ // Create a new config object
+ r = pakfire_config_create(&c);
+ if (r < 0)
+ goto ERROR;
+
// Open the distro configuration
if (config->distro) {
f = open_distro_config(config->distro);
}
}
+ // Read the configuration file
+ r = pakfire_config_read(c, f);
+ if (r < 0)
+ goto ERROR;
+
// Initialize Pakfire
- r = pakfire_create(&p, config->ctx, config->root, config->arch, f, config->flags);
+ r = pakfire_create(&p, config->ctx, c, config->root, config->arch, config->flags);
if (r < 0) {
fprintf(stderr, "Could not initialize Pakfire: %s\n", strerror(-r));
goto ERROR;
*pakfire = p;
ERROR:
+ if (c)
+ pakfire_config_unref(c);
if (f)
fclose(f);
int pakfire_config_dump(struct pakfire_config* config, FILE* f) {
return pakfire_config_walk_sections(config, pakfire_config_dump_section, f);
}
-
-FILE* pakfire_config_fdump(struct pakfire_config* config) {
- FILE* f = NULL;
- int r;
-
- char* buffer = NULL;
- size_t length = 0;
-
- // Open a new memory stream
- f = open_memstream(&buffer, &length);
- if (!f)
- goto ERROR;
-
- // Dump the configuration
- r = pakfire_config_dump(config, f);
- if (r < 0)
- goto ERROR;
-
- // Close the memory stream
- fclose(f);
-
- // Re-open as a new file handle
- f = fmemopen(buffer, length, "r");
- if (!f)
- goto ERROR;
-
- return f;
-
-ERROR:
- if (buffer)
- free(buffer);
-
- return NULL;
-}
#ifndef PAKFIRE_CONFIG_H
#define PAKFIRE_CONFIG_H
-#ifdef PAKFIRE_PRIVATE
-
#include <stdio.h>
struct pakfire_config;
int pakfire_config_parse(struct pakfire_config* config, const char* s, ssize_t length);
int pakfire_config_dump(struct pakfire_config* config, FILE* f);
-FILE* pakfire_config_fdump(struct pakfire_config* config);
-
-#endif
#endif /* PAKFIRE_CONFIG_H */
}
int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
- const char* path, const char* arch, FILE* conf, int flags) {
+ struct pakfire_config* config, const char* path, const char* arch, int flags) {
struct pakfire* p = NULL;
int r;
// Store the flags
p->flags = flags;
+ // Store a reference to the configuration
+ if (config) {
+ p->config = pakfire_config_ref(config);
+ } else {
+ r = pakfire_config_create(&p->config);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Store the nominal architecture
r = pakfire_string_set(p->arches.nominal, arch);
if (r < 0)
if (path)
p->internal_flags |= PAKFIRE_HAS_PATH;
- // Initialise configuration
- r = pakfire_config_create(&p->config);
- if (r < 0)
- goto ERROR;
-
- // Read the configuration file
- if (conf) {
- r = pakfire_config_read(p->config, conf);
- if (r < 0) {
- ERROR(p->ctx, "Could not read configuration: %s\n", strerror(-r));
- goto ERROR;
- }
- }
-
// Import distro configuration
r = pakfire_config_import_distro(p);
if (r < 0) {
int pakfire_clone(struct pakfire** clone, struct pakfire* pakfire, const char* path) {
struct pakfire* p = NULL;
- FILE* f = NULL;
int r;
- // Dump the configuration
- f = pakfire_config_fdump(pakfire->config);
- if (!f) {
- r = -errno;
- goto ERROR;
- }
-
// Create a new Pakfire instance
- r = pakfire_create(&p, pakfire->ctx, path, pakfire->arches.nominal, f, 0);
+ r = pakfire_create(&p, pakfire->ctx, pakfire->config, path, pakfire->arches.nominal, 0);
if (r < 0)
- goto ERROR;
+ return r;
// Return the pointer
- *clone = pakfire_ref(p);
+ *clone = p;
-ERROR:
- if (p)
- pakfire_unref(p);
- if (f)
- fclose(f);
-
- return r;
+ return 0;
}
struct pakfire* pakfire_ref(struct pakfire* pakfire) {
struct pakfire;
+#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/filelist.h>
#include <pakfire/key.h>
int progress, const char* status);
int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
- const char* path, const char* arch, FILE* conf, int flags);
+ struct pakfire_config* config, const char* path, const char* arch, int flags);
struct pakfire* pakfire_ref(struct pakfire* pakfire);
struct pakfire* pakfire_unref(struct pakfire* pakfire);
#include <pakfire/archive.h>
#include <pakfire/build.h>
+#include <pakfire/config.h>
#include <pakfire/constants.h>
#include <pakfire/ctx.h>
#include <pakfire/dist.h>
}
static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
+ struct pakfire_config* c = NULL;
const char* kwlist[] = { "ctx", "path", "arch", "conf", NULL };
CtxObject* ctx = NULL;
const char* path = NULL;
PyObject* conf = Py_None;
int r = 1;
- FILE* fconf = NULL;
+ FILE* f = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|zzO", (char**)kwlist,
&CtxType, &ctx, &path, &arch, &conf))
goto ERROR;
+ // Create a new configuration object
+ r = pakfire_config_create(&c);
+ if (r < 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto ERROR;
+ }
+
// Map the configuration
if (conf != Py_None) {
- fconf = PyObject_AsFileHandle(conf, "r");
- if (!fconf)
+ f = PyObject_AsFileHandle(conf, "r");
+ if (!f)
goto ERROR;
+
+ // Read the configuration
+ r = pakfire_config_read(c, f);
+ if (r < 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto ERROR;
+ }
}
int flags = 0;
self->ctx = pakfire_ctx_ref(ctx->ctx);
// Create a new Pakfire instance
- r = pakfire_create(&self->pakfire, self->ctx, path, arch, fconf, flags);
+ r = pakfire_create(&self->pakfire, self->ctx, c, path, arch, flags);
Py_END_ALLOW_THREADS
}
ERROR:
- if (fconf)
- fclose(fconf);
+ if (c)
+ pakfire_config_unref(c);
+ if (f)
+ fclose(f);
return -r;
}
pakfire_ctx_set_log_callback(ctx, pakfire_log_stderr, NULL);
// Create a pakfire instance
- r = pakfire_create(&pakfire, ctx, root, NULL, NULL, 0);
+ r = pakfire_create(&pakfire, ctx, NULL, root, NULL, 0);
if (r) {
fprintf(stderr, "Could not create Pakfire: %m\n");
goto ERROR;