"filename TEXT, "
"size INTEGER, "
"inst_size INTEGER, "
- "digest_sha512 TEXT, "
- "digest_sha256 TEXT, "
+ "digest TEXT, "
"license TEXT, "
"summary TEXT, "
"description TEXT, "
queue_push2(&pool->pooljobs, SOLVER_USERINSTALLED|SOLVER_SOLVABLE_NAME, id);
}
+static const struct pakfire_digest {
+ enum pakfire_digests type;
+ const char* prefix;
+} pakfire_digests[] = {
+ { PAKFIRE_DIGEST_SHA512, "sha512:" },
+ { PAKFIRE_DIGEST_SHA256, "sha256:" },
+ { PAKFIRE_DIGEST_NONE, NULL },
+};
+
+static char* pakfire_db_pack_digest(enum pakfire_digests 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_digests* type) {
+ *type = PAKFIRE_DIGEST_NONE;
+
+ // 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
goto ROLLBACK;
const char* sql = "INSERT INTO packages(name, evr, arch, groups, filename, size, "
- "inst_size, digest_sha512, digest_sha256, license, summary, description, uuid, "
+ "inst_size, digest, license, summary, description, uuid, "
"vendor, build_host, build_time, installed, repository, userinstalled) "
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)";
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)";
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
goto ROLLBACK;
}
- enum pakfire_digests digest = PAKFIRE_DIGEST_NONE;
+ enum pakfire_digests digest_type = PAKFIRE_DIGEST_NONE;
- const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest);
- switch (digest) {
- case PAKFIRE_DIGEST_SHA512:
- r = sqlite3_bind_text(stmt, 8, hexdigest, -1, NULL);
- if (r) {
- ERROR(db->pakfire, "Could not bind digest_sha512: %s\n", sqlite3_errmsg(db->handle));
- goto ROLLBACK;
- }
- break;
-
- case PAKFIRE_DIGEST_SHA256:
- r = sqlite3_bind_text(stmt, 9, hexdigest, -1, NULL);
- if (r) {
- ERROR(db->pakfire, "Could not bind digest_sha256: %s\n", sqlite3_errmsg(db->handle));
- goto ROLLBACK;
- }
+ const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest_type);
+ if (hexdigest) {
+ digest = pakfire_db_pack_digest(digest_type, hexdigest);
+ if (!digest)
+ goto ROLLBACK;
- case PAKFIRE_DIGEST_NONE:
- break;
+ 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 ROLLBACK;
+ }
}
// Bind license
const char* license = pakfire_package_get_license(pkg);
- r = sqlite3_bind_text(stmt, 10, license, -1, NULL);
+ r = sqlite3_bind_text(stmt, 9, license, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind license: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
// Bind summary
const char* summary = pakfire_package_get_summary(pkg);
- r = sqlite3_bind_text(stmt, 11, summary, -1, NULL);
+ r = sqlite3_bind_text(stmt, 10, summary, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind summary: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
// Bind description
const char* description = pakfire_package_get_description(pkg);
- r = sqlite3_bind_text(stmt, 12, description, -1, NULL);
+ r = sqlite3_bind_text(stmt, 11, description, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind description: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
// Bind uuid
const char* uuid = pakfire_package_get_uuid(pkg);
- r = sqlite3_bind_text(stmt, 13, uuid, -1, NULL);
+ r = sqlite3_bind_text(stmt, 12, uuid, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
// Bind vendor
const char* vendor = pakfire_package_get_vendor(pkg);
- r = sqlite3_bind_text(stmt, 14, vendor, -1, NULL);
+ r = sqlite3_bind_text(stmt, 13, vendor, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind vendor: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
// Bind build_host
const char* build_host = pakfire_package_get_build_host(pkg);
- r = sqlite3_bind_text(stmt, 15, build_host, -1, NULL);
+ r = sqlite3_bind_text(stmt, 14, build_host, -1, NULL);
if (r) {
ERROR(db->pakfire, "Could not bind build_host: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
// Bind build_time
time_t build_time = pakfire_package_get_build_time(pkg);
- r = sqlite3_bind_int64(stmt, 16, build_time);
+ r = sqlite3_bind_int64(stmt, 15, build_time);
if (r) {
ERROR(db->pakfire, "Could not bind build_time: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
const char* repo_name = pakfire_repo_get_name(repo);
pakfire_repo_unref(repo);
- r = sqlite3_bind_text(stmt, 17, repo_name, -1, NULL);
+ r = sqlite3_bind_text(stmt, 16, repo_name, -1, NULL);
if (r)
goto ROLLBACK;
// No repository?
} else {
- r = sqlite3_bind_null(stmt, 17);
+ r = sqlite3_bind_null(stmt, 16);
if (r)
goto ROLLBACK;
}
// installed by the user?
- r = sqlite3_bind_int(stmt, 18, userinstalled);
+ r = sqlite3_bind_int(stmt, 17, userinstalled);
if (r) {
ERROR(db->pakfire, "Could not bind userinstalled: %s\n", sqlite3_errmsg(db->handle));
goto ROLLBACK;
ROLLBACK:
if (stmt)
sqlite3_finalize(stmt);
+ if (digest)
+ free(digest);
pakfire_db_rollback(db);
pakfire_package_set_installsize(pkg, size);
}
- // Digest SHA512
- const char* digest_sha512 = (const char*)sqlite3_column_text(stmt, 8);
- if (digest_sha512) {
- pakfire_package_set_hexdigest(pkg, PAKFIRE_DIGEST_SHA512, digest_sha512);
- }
+ // Digest
+ const char* digest = (const char*)sqlite3_column_text(stmt, 8);
+ if (digest) {
+ enum pakfire_digests digest_type = PAKFIRE_DIGEST_NONE;
- // Digest SHA256
- const char* digest_sha256 = (const char*)sqlite3_column_text(stmt, 9);
- if (digest_sha256) {
- pakfire_package_set_hexdigest(pkg, PAKFIRE_DIGEST_SHA256, digest_sha256);
+ // Unpack digest
+ const char* hexdigest = pakfire_db_unpack_digest(digest, &digest_type);
+ if (hexdigest)
+ pakfire_package_set_hexdigest(pkg, digest_type, hexdigest);
}
// License
- const char* license = (const char*)sqlite3_column_text(stmt, 10);
+ const char* license = (const char*)sqlite3_column_text(stmt, 9);
if (license) {
pakfire_package_set_license(pkg, license);
}
// Summary
- const char* summary = (const char*)sqlite3_column_text(stmt, 11);
+ const char* summary = (const char*)sqlite3_column_text(stmt, 10);
if (summary) {
pakfire_package_set_summary(pkg, summary);
}
// Description
- const char* description = (const char*)sqlite3_column_text(stmt, 12);
+ const char* description = (const char*)sqlite3_column_text(stmt, 11);
if (description) {
pakfire_package_set_description(pkg, description);
}
// UUID
- const char* uuid = (const char*)sqlite3_column_text(stmt, 13);
+ const char* uuid = (const char*)sqlite3_column_text(stmt, 12);
if (uuid) {
pakfire_package_set_uuid(pkg, uuid);
}
// Vendor
- const char* vendor = (const char*)sqlite3_column_text(stmt, 14);
+ const char* vendor = (const char*)sqlite3_column_text(stmt, 13);
if (vendor) {
pakfire_package_set_vendor(pkg, vendor);
}
// Build Host
- const char* build_host = (const char*)sqlite3_column_text(stmt, 15);
+ const char* build_host = (const char*)sqlite3_column_text(stmt, 14);
if (build_host) {
pakfire_package_set_build_host(pkg, build_host);
}
// Build Time
- time_t build_time = sqlite3_column_int64(stmt, 16);
+ time_t build_time = sqlite3_column_int64(stmt, 15);
if (build_time) {
pakfire_package_set_build_time(pkg, build_time);
}
// Install Time
- time_t install_time = sqlite3_column_int64(stmt, 17);
+ time_t install_time = sqlite3_column_int64(stmt, 16);
if (install_time) {
pakfire_package_set_install_time(pkg, install_time);
}
// installed by user?
- int userinstalled = sqlite3_column_int(stmt, 18);
+ int userinstalled = sqlite3_column_int(stmt, 17);
if (userinstalled)
pakfire_db_add_userinstalled(db->pakfire, name);
// Files
- const char* files = (const char*)sqlite3_column_text(stmt, 19);
+ const char* files = (const char*)sqlite3_column_text(stmt, 18);
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[] = {
- { 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 },
+ { 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 },
{ 0, NULL },
};
const char* sql =
"SELECT "
"name, evr, arch, id, groups, filename, size, inst_size, "
- "digest_sha512, digest_sha256, license, summary, description, uuid, vendor, "
+ "digest, license, summary, description, uuid, vendor, "
"build_host, build_time, strftime('%s', installed) AS installed, userinstalled, "
"("
"SELECT group_concat(path, '\n') FROM files WHERE files.pkg = packages.id"