queue_push2(&pool->pooljobs, SOLVER_USERINSTALLED|SOLVER_SOLVABLE_NAME, id);
}
-static const struct pakfire_digest {
- enum pakfire_digest_types type;
- const char* prefix;
-} pakfire_digests[] = {
- { PAKFIRE_DIGEST_SHA2_512, "sha512:" },
- { PAKFIRE_DIGEST_SHA2_256, "sha256:" },
- { 0, NULL },
-};
-
-static char* pakfire_db_pack_digest(enum pakfire_digest_types type, const char* hexdigest) {
- char* s = NULL;
- int r;
-
- for (const struct pakfire_digest* digest = pakfire_digests; digest->type; digest++) {
- if (digest->type == type) {
- r = asprintf(&s, "%s%s", digest->prefix, hexdigest);
- if (r < 0)
- return NULL;
-
- return s;
- }
- }
-
- return NULL;
-}
-
-static const char* pakfire_db_unpack_digest(const char* hexdigest, enum pakfire_digest_types* type) {
- *type = 0;
-
- // Don't do anything for empty input
- if (!hexdigest || !*hexdigest)
- return NULL;
-
- for (const struct pakfire_digest* digest = pakfire_digests; digest->type; digest++) {
- if (pakfire_string_startswith(hexdigest, digest->prefix)) {
- *type = digest->type;
-
- // Return the beginning of the hexdigest
- return hexdigest + strlen(digest->prefix);
- }
- }
-
- // No match
- return NULL;
-}
-
static int pakfire_db_add_dependencies(struct pakfire_db* db, unsigned long id, struct pakfire_package* pkg) {
sqlite3_stmt* stmt = NULL;
int r = 1;
int pakfire_db_add_package(struct pakfire_db* db,
struct pakfire_package* pkg, struct pakfire_archive* archive, int userinstalled) {
sqlite3_stmt* stmt = NULL;
- char* digest = NULL;
int r;
// Begin a new transaction
"filename, "
"size, "
"inst_size, "
+ "digest_type, "
"digest, "
"license, "
"summary, "
"?, "
"?, "
"?, "
+ "?, "
"CURRENT_TIMESTAMP, "
"?, "
"?, "
goto ERROR;
}
+ const unsigned char* digest = NULL;
enum pakfire_digest_types digest_type = 0;
+ size_t digest_length = 0;
- const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest_type);
- if (hexdigest) {
- digest = pakfire_db_pack_digest(digest_type, hexdigest);
- if (!digest)
- goto ERROR;
+ // Fetch the digest
+ digest = pakfire_package_get_digest(pkg, &digest_type, &digest_length);
+ if (!digest) {
+ ERROR(db->pakfire, "Could not fetch the package's digest: %m\n");
+ r = 1;
+ goto ERROR;
+ }
- r = sqlite3_bind_text(stmt, 8, digest, -1, NULL);
- if (r) {
- ERROR(db->pakfire, "Could not bind digest: %s\n", sqlite3_errmsg(db->handle));
- goto ERROR;
- }
+ // Set the digest type
+ r = sqlite3_bind_int64(stmt, 8, digest_type);
+ if (r) {
+ ERROR(db->pakfire, "Could not bind digest type: %s\n", sqlite3_errmsg(db->handle));
+ goto ERROR;
+ }
+
+ // Set the digest
+ r = sqlite3_bind_blob(stmt, 9, digest, digest_length, NULL);
+ if (r) {
+ ERROR(db->pakfire, "Could not bind digest: %s\n", sqlite3_errmsg(db->handle));
+ goto ERROR;
}
// Bind license
const char* license = pakfire_package_get_license(pkg);
- r = sqlite3_bind_text(stmt, 9, license, -1, NULL);
+ r = sqlite3_bind_text(stmt, 10, license, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind license: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Bind summary
const char* summary = pakfire_package_get_summary(pkg);
- r = sqlite3_bind_text(stmt, 10, summary, -1, NULL);
+ r = sqlite3_bind_text(stmt, 11, summary, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind summary: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Bind description
const char* description = pakfire_package_get_description(pkg);
- r = sqlite3_bind_text(stmt, 11, description, -1, NULL);
+ r = sqlite3_bind_text(stmt, 12, description, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind description: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Bind uuid
const char* uuid = pakfire_package_get_uuid(pkg);
- r = sqlite3_bind_text(stmt, 12, uuid, -1, NULL);
+ r = sqlite3_bind_text(stmt, 13, uuid, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Bind vendor
const char* vendor = pakfire_package_get_vendor(pkg);
- r = sqlite3_bind_text(stmt, 13, vendor, -1, NULL);
+ r = sqlite3_bind_text(stmt, 14, vendor, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind vendor: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Bind build_host
const char* build_host = pakfire_package_get_build_host(pkg);
- r = sqlite3_bind_text(stmt, 14, build_host, -1, NULL);
+ r = sqlite3_bind_text(stmt, 15, build_host, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind build_host: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Bind build_time
time_t build_time = pakfire_package_get_build_time(pkg);
- r = sqlite3_bind_int64(stmt, 15, build_time);
+ r = sqlite3_bind_int64(stmt, 16, build_time);
if (r) {
ERROR(db->pakfire, "Could not bind build_time: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
const char* repo_name = pakfire_repo_get_name(repo);
pakfire_repo_unref(repo);
- r = sqlite3_bind_text(stmt, 16, repo_name, -1, NULL);
+ r = sqlite3_bind_text(stmt, 17, repo_name, -1, NULL);
if (r)
goto ERROR;
// No repository?
} else {
- r = sqlite3_bind_null(stmt, 16);
+ r = sqlite3_bind_null(stmt, 17);
if (r)
goto ERROR;
}
// installed by the user?
- r = sqlite3_bind_int(stmt, 17, userinstalled);
+ r = sqlite3_bind_int(stmt, 18, userinstalled);
if (r) {
ERROR(db->pakfire, "Could not bind userinstalled: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
// Source package name
const char* source_name = pakfire_package_get_source_name(pkg);
if (source_name) {
- r = sqlite3_bind_text(stmt, 18, source_name, -1, NULL);
+ r = sqlite3_bind_text(stmt, 19, source_name, -1, NULL);
if (r)
goto ERROR;
} else {
- r = sqlite3_bind_null(stmt, 18);
+ r = sqlite3_bind_null(stmt, 19);
if (r)
goto ERROR;
}
// Source EVR
const char* source_evr = pakfire_package_get_source_evr(pkg);
if (source_evr) {
- r = sqlite3_bind_text(stmt, 19, source_evr, -1, NULL);
+ r = sqlite3_bind_text(stmt, 20, source_evr, -1, NULL);
if (r)
goto ERROR;
} else {
- r = sqlite3_bind_null(stmt, 19);
+ r = sqlite3_bind_null(stmt, 20);
if (r)
goto ERROR;
}
// Source arch
const char* source_arch = pakfire_package_get_source_arch(pkg);
if (source_arch) {
- r = sqlite3_bind_text(stmt, 20, source_arch, -1, NULL);
+ r = sqlite3_bind_text(stmt, 21, source_arch, -1, NULL);
if (r)
goto ERROR;
} else {
- r = sqlite3_bind_null(stmt, 20);
+ r = sqlite3_bind_null(stmt, 21);
if (r)
goto ERROR;
}
// Distribution
const char* distribution = pakfire_package_get_distribution(pkg);
if (distribution) {
- r = sqlite3_bind_text(stmt, 21, distribution, -1, NULL);
+ r = sqlite3_bind_text(stmt, 22, distribution, -1, NULL);
if (r)
goto ERROR;
} else {
- r = sqlite3_bind_null(stmt, 21);
+ r = sqlite3_bind_null(stmt, 22);
if (r)
goto ERROR;
}
ERROR:
if (stmt)
sqlite3_finalize(stmt);
- if (digest)
- free(digest);
// Commit or rollback
if (r)
pakfire_package_set_installsize(pkg, size);
}
- // Digest
- const char* digest = (const char*)sqlite3_column_text(stmt, 8);
- if (digest) {
- enum pakfire_digest_types digest_type = 0;
+ // Digest type
+ enum pakfire_digest_types digest_type = sqlite3_column_int64(stmt, 8);
+ size_t digest_length = 0;
- // Unpack digest
- const char* hexdigest = pakfire_db_unpack_digest(digest, &digest_type);
- if (hexdigest)
- pakfire_package_set_hexdigest(pkg, digest_type, hexdigest);
+ // Digest length
+
+ // Digest
+ const unsigned char* digest = sqlite3_column_blob(stmt, 9);
+ if (digest_type && digest) {
+ pakfire_package_set_digest(pkg, digest_type, digest, digest_length);
}
// License
- const char* license = (const char*)sqlite3_column_text(stmt, 9);
+ const char* license = (const char*)sqlite3_column_text(stmt, 10);
if (license) {
pakfire_package_set_license(pkg, license);
}
// Summary
- const char* summary = (const char*)sqlite3_column_text(stmt, 10);
+ const char* summary = (const char*)sqlite3_column_text(stmt, 11);
if (summary) {
pakfire_package_set_summary(pkg, summary);
}
// Description
- const char* description = (const char*)sqlite3_column_text(stmt, 11);
+ const char* description = (const char*)sqlite3_column_text(stmt, 12);
if (description) {
pakfire_package_set_description(pkg, description);
}
// UUID
- const char* uuid = (const char*)sqlite3_column_text(stmt, 12);
+ const char* uuid = (const char*)sqlite3_column_text(stmt, 13);
if (uuid) {
pakfire_package_set_uuid(pkg, uuid);
}
// Vendor
- const char* vendor = (const char*)sqlite3_column_text(stmt, 13);
+ const char* vendor = (const char*)sqlite3_column_text(stmt, 14);
if (vendor) {
pakfire_package_set_vendor(pkg, vendor);
}
// Build Host
- const char* build_host = (const char*)sqlite3_column_text(stmt, 14);
+ const char* build_host = (const char*)sqlite3_column_text(stmt, 15);
if (build_host) {
pakfire_package_set_build_host(pkg, build_host);
}
// Build Time
- time_t build_time = sqlite3_column_int64(stmt, 15);
+ time_t build_time = sqlite3_column_int64(stmt, 16);
if (build_time) {
pakfire_package_set_build_time(pkg, build_time);
}
// Install Time
- time_t install_time = sqlite3_column_int64(stmt, 16);
+ time_t install_time = sqlite3_column_int64(stmt, 17);
if (install_time) {
pakfire_package_set_install_time(pkg, install_time);
}
// installed by user?
- int userinstalled = sqlite3_column_int(stmt, 17);
+ int userinstalled = sqlite3_column_int(stmt, 18);
if (userinstalled)
pakfire_db_add_userinstalled(db->pakfire, name);
// Files
- const char* files = (const char*)sqlite3_column_text(stmt, 18);
+ const char* files = (const char*)sqlite3_column_text(stmt, 19);
if (files) {
r = pakfire_package_set_filelist_from_string(pkg, files);
if (r)
unsigned int field;
void (*func)(struct pakfire_package* pkg, const char* dep);
} dependencies[] = {
- { 19, pakfire_package_add_provides },
- { 20, pakfire_package_add_prerequires },
- { 21, pakfire_package_add_requires },
- { 22, pakfire_package_add_conflicts },
- { 23, pakfire_package_add_obsoletes },
- { 24, pakfire_package_add_recommends },
- { 25, pakfire_package_add_suggests },
- { 26, pakfire_package_add_supplements },
- { 27, pakfire_package_add_enhances },
+ { 20, pakfire_package_add_provides },
+ { 21, pakfire_package_add_prerequires },
+ { 22, pakfire_package_add_requires },
+ { 23, pakfire_package_add_conflicts },
+ { 24, pakfire_package_add_obsoletes },
+ { 25, pakfire_package_add_recommends },
+ { 26, pakfire_package_add_suggests },
+ { 27, pakfire_package_add_supplements },
+ { 28, pakfire_package_add_enhances },
{ 0, NULL },
};
}
// Source package
- const char* source_name = (const char*)sqlite3_column_text(stmt, 28);
+ const char* source_name = (const char*)sqlite3_column_text(stmt, 29);
if (source_name)
pakfire_package_set_source_name(pkg, source_name);
// Source EVR
- const char* source_evr = (const char*)sqlite3_column_text(stmt, 29);
+ const char* source_evr = (const char*)sqlite3_column_text(stmt, 30);
if (source_evr)
pakfire_package_set_source_evr(pkg, source_evr);
// Source arch
- const char* source_arch = (const char*)sqlite3_column_text(stmt, 30);
+ const char* source_arch = (const char*)sqlite3_column_text(stmt, 31);
if (source_arch)
pakfire_package_set_source_arch(pkg, source_arch);
// Distribution
- const char* distribution = (const char*)sqlite3_column_text(stmt, 31);
+ const char* distribution = (const char*)sqlite3_column_text(stmt, 32);
if (distribution)
pakfire_package_set_distribution(pkg, distribution);
"filename, "
"size, "
"inst_size, "
+ "digest_type, "
"digest, "
"license, "
"summary, "