#include <solv/repo.h>
#include <solv/solvable.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
#include <pakfire/archive.h>
#include <pakfire/constants.h>
#include <pakfire/ctx.h>
int pakfire_package_create_from_solvable(struct pakfire_package** package,
struct pakfire* pakfire, Id id) {
- struct pakfire_package* pkg = calloc(1, sizeof(*pkg));
+ struct pakfire_package* pkg = NULL;
+
+ // Allocate some memory
+ pkg = calloc(1, sizeof(*pkg));
if (!pkg)
- return 1;
+ return -errno;
// Store a reference to the context
pkg->ctx = pakfire_ctx(pakfire);
+ // Store a reference to Pakfire
pkg->pakfire = pakfire_ref(pakfire);
+
+ // Initialize the reference counter
pkg->nrefs = 1;
// Store the ID
// Success
*package = pkg;
+
return 0;
}
repo = dummy;
}
+ // Fetch the context
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
// Allocate a new solvable
Id id = pakfire_repo_add_solvable(repo);
if (!id) {
- ERROR(pakfire, "Could not allocate a solvable: %m\n");
+ CTX_ERROR(ctx, "Could not allocate a solvable: %m\n");
r = 1;
goto ERROR;
}
// 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);
+ CTX_ERROR(ctx, "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);
+ CTX_ERROR(ctx, "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);
+ CTX_ERROR(ctx, "Could not set package arch '%s': %m\n", arch);
goto ERROR;
}
// Add self-provides
r = pakfire_package_add_self_provides(*package);
if (r) {
- ERROR(pakfire, "Could not create self-provides: %m\n");
+ CTX_ERROR(ctx, "Could not create self-provides: %m\n");
goto ERROR;
}
ERROR:
if (dummy)
pakfire_repo_unref(dummy);
+ if (ctx)
+ pakfire_ctx_unref(ctx);
return r;
}
// Fetch the filename
const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
if (!filename) {
- ERROR(pkg->pakfire, "Could not fetch filename for %s: %m\n", nevra);
+ CTX_ERROR(pkg->ctx, "Could not fetch filename for %s: %m\n", nevra);
return 1;
}
// Fetch UUID
const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
if (!uuid) {
- ERROR(pkg->pakfire, "Could not fetch UUID for %s: %m\n", nevra);
+ CTX_ERROR(pkg->ctx, "Could not fetch UUID for %s: %m\n", nevra);
return 1;
}
// Open archive
r = pakfire_archive_open(&archive, pkg->pakfire, path);
if (r) {
- ERROR(pkg->pakfire, "Could not open archive for %s (at %s): %m\n",
+ CTX_ERROR(pkg->ctx, "Could not open archive for %s (at %s): %m\n",
pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA), path);
goto ERROR;
}
// Fetch repodata
struct pakfire_repo* repo = pakfire_package_get_repo(pkg);
if (!repo) {
- ERROR(pkg->pakfire, "Could not find repository for %s: %m\n",
+ CTX_ERROR(pkg->ctx, "Could not find repository for %s: %m\n",
pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA));
return 1;
}
// Fetch the filelist
filelist = pakfire_package_get_filelist(pkg);
if (!filelist) {
- ERROR(pkg->pakfire, "Could not fetch package filelist\n");
+ CTX_ERROR(pkg->ctx, "Could not fetch package filelist\n");
r = 1;
goto ERROR;
}
// Create a new JSON array
object = json_object_new_array();
if (!object) {
- ERROR(pkg->pakfire, "Could not create a JSON array\n");
+ CTX_ERROR(pkg->ctx, "Could not create a JSON array\n");
r = 1;
goto ERROR;
}
// Create a new JSON array
object = json_object_new_object();
if (!object) {
- ERROR(pkg->pakfire, "Could not create a new JSON object: %m\n");
+ CTX_ERROR(pkg->ctx, "Could not create a new JSON object: %m\n");
r = 1;
goto ERROR;
}
// Fetch the installed repository
repo = pakfire_get_installed_repo(pkg->pakfire);
if (!repo) {
- ERROR(pkg->pakfire, "Could not fetch the installed repository: %m\n");
+ CTX_ERROR(pkg->ctx, "Could not fetch the installed repository: %m\n");
r = 1;
goto ERROR;
}
// Fetch all installed packages
r = pakfire_repo_to_packagelist(repo, packages);
if (r) {
- ERROR(pkg->pakfire, "Could not fetch packages from installed repository: %m\n");
+ CTX_ERROR(pkg->ctx, "Could not fetch packages from installed repository: %m\n");
goto ERROR;
}
r = pakfire_transaction_request_package(transaction,
PAKFIRE_JOB_INSTALL, pkg, PAKFIRE_JOB_ESSENTIAL);
if (r) {
- ERROR(pkg->pakfire, "Could not add package %s to the request\n", nevra);
+ CTX_ERROR(pkg->ctx, "Could not add package %s to the request\n", nevra);
goto ERROR;
}
// Solve the transaction
r = pakfire_transaction_solve(transaction, PAKFIRE_TRANSACTION_WITHOUT_RECOMMENDED, &p);
if (r) {
- DEBUG(pkg->pakfire, "Could not install %s:\n%s\n", nevra, p);
+ CTX_DEBUG(pkg->ctx, "Could not install %s:\n%s\n", nevra, p);
// Copy the problem string
if (p)