&name, &evr, &arch))
return -1;
- self->package = pakfire_package_create(pakfire->pakfire, repo->repo, name, evr, arch);
- if (!self->package) {
+ int r = pakfire_package_create(&self->package, pakfire->pakfire, repo->repo, name, evr, arch);
+ if (r) {
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
return NULL;
struct pakfire* pakfire = pakfire_repo_get_pakfire(self->repo);
- struct pakfire_package* pkg = pakfire_package_create(pakfire, self->repo, name, evr, arch);
+ struct pakfire_package* pkg = NULL;
+
+ int r = pakfire_package_create(&pkg, pakfire, self->repo, name, evr, arch);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
PyObject* obj = new_package(&PackageType, pkg);
static int pakfire_archive_make_package_from_json(struct pakfire_archive* archive,
struct pakfire_repo* repo, struct pakfire_package** package) {
+ struct pakfire_package* pkg = NULL;
struct pakfire_filelist* filelist = NULL;
int r;
const char* arch = pakfire_archive_metadata_get(archive, "arch", NULL);
// Create a new package object
- struct pakfire_package* pkg = pakfire_package_create(archive->pakfire,
- repo, name, evr, arch);
- if (!pkg)
- return 1;
+ r = pakfire_package_create(&pkg, archive->pakfire, repo, name, evr, arch);
+ if (r)
+ return r;
#ifdef ENABLE_DEBUG
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
free(type);
}
- struct pakfire_package* pkg = pakfire_package_create(
- archive->pakfire, repo, name, evr, (arch) ? arch : "src"
- );
+ struct pakfire_package* pkg = NULL;
+
+ r = pakfire_package_create(&pkg, archive->pakfire, repo, name, evr,
+ (arch) ? arch : "src");
if (name)
free(name);
if (arch)
free(arch);
+ if (r)
+ goto ERROR;
+
// Set package pointer right here to avoid an endless loop when loading the filelist
*package = pkg;
}
// Create package
- pkg = pakfire_package_create(db->pakfire, repo, name, evr, arch);
- if (!pkg) {
+ r = pakfire_package_create(&pkg, db->pakfire, repo, name, evr, arch);
+ if (r) {
ERROR(db->pakfire, "Could not create package\n");
goto ERROR;
}
PAKFIRE_PKG_MAINTAINER,
};
-struct pakfire_package* pakfire_package_create(struct pakfire* pakfire, struct pakfire_repo* repo,
- const char* name, const char* evr, const char* arch);
+int pakfire_package_create(struct pakfire_package** package, struct pakfire* pakfire,
+ struct pakfire_repo* repo, const char* name, const char* evr, const char* arch);
struct pakfire_package* pakfire_package_ref(struct pakfire_package* pkg);
struct pakfire_package* pakfire_package_unref(struct pakfire_package* pkg);
#include <solv/pooltypes.h>
#include <uuid/uuid.h>
-struct pakfire_package* pakfire_package_create_from_solvable(struct pakfire* pakfire, Id id);
+int pakfire_package_create_from_solvable(struct pakfire_package** package,
+ struct pakfire* pakfire, Id id);
void pakfire_package_set_build_id_from_uuid(struct pakfire_package* pkg, uuid_t* build_id);
uint64_t pakfire_package_get_dbid(struct pakfire_package* pkg);
char path[PATH_MAX];
};
-struct pakfire_package* pakfire_package_create_from_solvable(struct pakfire* pakfire, Id id) {
+int pakfire_package_create_from_solvable(struct pakfire_package** package,
+ struct pakfire* pakfire, Id id) {
struct pakfire_package* pkg = calloc(1, sizeof(*pkg));
if (!pkg)
- return NULL;
+ return 1;
pkg->pakfire = pakfire_ref(pakfire);
- pkg->id = id;
-
- // Initialize reference counter
pkg->nrefs = 1;
- return pkg;
+ // Store the ID
+ pkg->id = id;
+
+ // Success
+ *package = pkg;
+ return 0;
}
-PAKFIRE_EXPORT struct pakfire_package* pakfire_package_create(
+PAKFIRE_EXPORT int pakfire_package_create(struct pakfire_package** package,
struct pakfire* pakfire, struct pakfire_repo* repo,
const char* name, const char* evr, const char* arch) {
- struct pakfire_package* pkg = NULL;
struct pakfire_repo* dummy = NULL;
+ int r;
+
+ // Check for some valid input
+ if (!name || !evr || !arch) {
+ errno = EINVAL;
+ return 1;
+ }
// Default to dummy repository
if (!repo) {
dummy = pakfire_get_repo(pakfire, PAKFIRE_REPO_DUMMY);
if (!dummy) {
errno = ENOENT;
- return NULL;
+ return 1;
}
repo = dummy;
// Allocate a new solvable
Id id = pakfire_repo_add_solvable(repo);
- if (!id)
+ if (!id) {
+ ERROR(pakfire, "Could not allocate a solvable: %m\n");
+ r = 1;
goto ERROR;
+ }
// Create a new package object
- pkg = pakfire_package_create_from_solvable(pakfire, id);
- if (!pkg)
+ r = pakfire_package_create_from_solvable(package, pakfire, id);
+ if (r)
goto ERROR;
- pkg->repo = pakfire_repo_ref(repo);
+ // Reference the repository
+ (*package)->repo = pakfire_repo_ref(repo);
- // Set the given attributes
- pakfire_package_set_string(pkg, PAKFIRE_PKG_NAME, name);
- pakfire_package_set_string(pkg, PAKFIRE_PKG_EVR, evr);
- pakfire_package_set_string(pkg, PAKFIRE_PKG_ARCH, arch);
+ // Set the name
+ r = pakfire_package_set_string(*package, PAKFIRE_PKG_NAME, name);
+ if (r) {
+ ERROR(pakfire, "Could not set package name '%s': %m\n", name);
+ goto ERROR;
+ }
+
+ // Set EVR
+ r = pakfire_package_set_string(*package, PAKFIRE_PKG_EVR, evr);
+ if (r) {
+ ERROR(pakfire, "Could not set package EVR '%s': %m\n", evr);
+ goto ERROR;
+ }
+
+ // Set arch
+ r = pakfire_package_set_string(*package, PAKFIRE_PKG_ARCH, arch);
+ if (r) {
+ ERROR(pakfire, "Could not set package arch '%s': %m\n", arch);
+ goto ERROR;
+ }
ERROR:
if (dummy)
pakfire_repo_unref(dummy);
- return pkg;
+ return r;
}
static void pakfire_package_free(struct pakfire_package* pkg) {
}
int pakfire_packagelist_create_from_queue(struct pakfire_packagelist** list, struct pakfire* pakfire, Queue* q) {
+ struct pakfire_package* pkg = NULL;
+
// Create a new package list
int r = pakfire_packagelist_create(list, pakfire);
if (r)
return r;
for (int i = 0; i < q->count; i++) {
- struct pakfire_package* pkg = pakfire_package_create_from_solvable(pakfire, q->elements[i]);
- if (!pkg)
+ r = pakfire_package_create_from_solvable(&pkg, pakfire, q->elements[i]);
+ if (r)
goto ERROR;
pakfire_packagelist_push(*list, pkg);
}
// Create a new package object
- *pkg = pakfire_package_create(parser->pakfire, repo, name, evr, arch);
- if (!*pkg) {
+ r = pakfire_package_create(pkg, parser->pakfire, repo, name, evr, arch);
+ if (r) {
ERROR(parser->pakfire, "Could not create package\n");
goto CLEANUP;
}
Id id = pool_solvable2id(pool, s);
// Allocate package
- pkg = pakfire_package_create_from_solvable(repo->pakfire, id);
- if (!pkg)
+ r = pakfire_package_create_from_solvable(&pkg, repo->pakfire, id);
+ if (r)
return 1;
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
static int pakfire_transaction_import_transaction(
struct pakfire_transaction* transaction, Solver* solver) {
+ int r;
+
// Clone the transaction to keep a copy of it
Transaction* t = solver_create_transaction(solver);
if (!t)
// Create all packages
for (unsigned int i = 0; i < transaction->num; i++) {
- transaction->packages[i] = pakfire_package_create_from_solvable(
+ r = pakfire_package_create_from_solvable(&transaction->packages[i],
transaction->pakfire, t->steps.elements[i]);
+ if (r)
+ return r;
}
return 0;
PAKFIRE_EXPORT char* pakfire_transaction_dump(struct pakfire_transaction* transaction, size_t width) {
char headline[1024];
+ int r;
Pool* pool = transaction->transaction->pool;
const int mode =
// List all packages
for (int j = 0; j < pkgs.count; j++) {
- struct pakfire_package* old_pkg = pakfire_package_create_from_solvable(
- transaction->pakfire, pkgs.elements[j]);
+ struct pakfire_package* old_pkg = NULL;
struct pakfire_package* new_pkg = NULL;
+ r = pakfire_package_create_from_solvable(&old_pkg, transaction->pakfire,
+ pkgs.elements[j]);
+ if (r)
+ continue;
+
switch (class) {
case SOLVER_TRANSACTION_UPGRADED:
case SOLVER_TRANSACTION_DOWNGRADED:
- new_pkg = pakfire_package_create_from_solvable(transaction->pakfire,
+ r = pakfire_package_create_from_solvable(&new_pkg, transaction->pakfire,
transaction_obs_pkg(transaction->transaction, pkgs.elements[j]));
+ if (r)
+ continue;
pakfire_transaction_add_package_change(&lines, width, old_pkg, new_pkg);
break;
struct pakfire_package* pkg = NULL;
int r = EXIT_FAILURE;
- ASSERT(pkg = pakfire_package_create(t->pakfire, NULL, "test", "1.0-1", "src"));
+ ASSERT_SUCCESS(pakfire_package_create(&pkg, t->pakfire, NULL, "test", "1.0-1", "src"));
ASSERT_STRING_EQUALS(pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME), "test");
ASSERT_STRING_EQUALS(pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR), "1.0-1");
ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
ASSERT(repo);
- pkg = pakfire_package_create(t->pakfire, repo,
- "test", "1.0-1", "src");
- ASSERT(pkg);
+ ASSERT_SUCCESS(pakfire_package_create(&pkg, t->pakfire, repo, "test", "1.0-1", "src"));
// Create packager
ASSERT_SUCCESS(pakfire_packager_create(&packager, t->pakfire, pkg));
struct pakfire_repo* repo = pakfire_get_repo(t->pakfire, PAKFIRE_REPO_DUMMY);
ASSERT(repo);
- pkg1 = pakfire_package_create(t->pakfire, repo,
- "test", "1.0-1", "x86_64");
- ASSERT(pkg1);
+ ASSERT_SUCCESS(pakfire_package_create(&pkg1, t->pakfire, repo,
+ "test", "1.0-1", "x86_64"));
// Set all metadata
pakfire_package_set_string(pkg1, PAKFIRE_PKG_SUMMARY, "SUMMARY");