#include <pakfire/archive.h>
#include <pakfire/db.h>
#include <pakfire/file.h>
+#include <pakfire/filelist.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
#include <pakfire/pakfire.h>
goto ERROR;
}
+ // ID
+ uint64_t id = sqlite3_column_int64(stmt, 3);
+ if (id)
+ pakfire_package_set_dbid(pkg, id);
+
// Groups
- const char* groups = (const char*)sqlite3_column_text(stmt, 3);
+ const char* groups = (const char*)sqlite3_column_text(stmt, 4);
if (groups) {
pakfire_package_set_groups(pkg, groups);
}
// Filename
- const char* filename = (const char*)sqlite3_column_text(stmt, 4);
+ const char* filename = (const char*)sqlite3_column_text(stmt, 5);
if (filename) {
pakfire_package_set_filename(pkg, filename);
}
// Size
- size_t size = sqlite3_column_int64(stmt, 5);
+ size_t size = sqlite3_column_int64(stmt, 6);
if (size) {
pakfire_package_set_downloadsize(pkg, size);
}
// Installed size
- size = sqlite3_column_int64(stmt, 6);
+ size = sqlite3_column_int64(stmt, 7);
if (size) {
pakfire_package_set_installsize(pkg, size);
}
// Hash 1
- const char* hash1 = (const char*)sqlite3_column_text(stmt, 7);
+ const char* hash1 = (const char*)sqlite3_column_text(stmt, 8);
if (hash1) {
pakfire_package_set_checksum(pkg, hash1);
}
// License
- const char* license = (const char*)sqlite3_column_text(stmt, 8);
+ 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, 9);
+ 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, 10);
+ 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, 11);
+ 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, 12);
+ 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, 13);
+ 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, 14);
+ 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, 15);
+ 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, 16);
+ 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, 17);
+ 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)(PakfirePackage pkg, const char* dep);
} dependencies[] = {
- { 18, pakfire_package_add_provides },
- { 19, pakfire_package_add_prerequires },
- { 20, pakfire_package_add_requires },
- { 21, pakfire_package_add_conflicts },
- { 22, pakfire_package_add_obsoletes },
- { 23, pakfire_package_add_recommends },
- { 24, pakfire_package_add_suggests },
- { 25, pakfire_package_add_supplements },
- { 26, 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, groups, filename, size, inst_size, hash1, license, summary, "
- "description, uuid, vendor, build_host, build_time, "
+ "name, evr, arch, id, groups, filename, size, inst_size, hash1, 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"
return r;
}
+
+static int pakfire_db_load_file(struct pakfire_db* db, PakfireFilelist filelist,
+ sqlite3_stmt* stmt) {
+ struct pakfire_file* file = NULL;
+ char abspath[PATH_MAX];
+ int r;
+
+ // Create a new file object
+ r = pakfire_file_create(&file, db->pakfire);
+ if (r)
+ goto ERROR;
+
+ // Path
+ const char* path = (const char*)sqlite3_column_text(stmt, 0);
+ if (path)
+ pakfire_file_set_path(file, path);
+
+ // Abspath
+ r = pakfire_make_path(db->pakfire, abspath, path);
+ if (r < 0)
+ goto ERROR;
+
+ pakfire_file_set_abspath(file, abspath);
+
+ // Size
+ size_t size = sqlite3_column_int64(stmt, 1);
+ if (size)
+ pakfire_file_set_size(file, size);
+
+ // Mode
+ mode_t mode = sqlite3_column_int(stmt, 2);
+ if (mode)
+ pakfire_file_set_mode(file, mode);
+
+ // User
+ const char* user = (const char*)sqlite3_column_text(stmt, 3);
+ if (user)
+ pakfire_file_set_user(file, user);
+
+ // Group
+ const char* group = (const char*)sqlite3_column_text(stmt, 4);
+ if (group)
+ pakfire_file_set_group(file, group);
+
+ // ctime
+ time_t ctime = sqlite3_column_int64(stmt, 5);
+ if (ctime)
+ pakfire_file_set_ctime(file, ctime);
+
+ // mtime
+ time_t mtime = sqlite3_column_int64(stmt, 6);
+ if (mtime)
+ pakfire_file_set_mtime(file, mtime);
+
+ // Append the file to the filelist
+ r = pakfire_filelist_append(filelist, file);
+
+ERROR:
+ if (file)
+ pakfire_file_unref(file);
+
+ return r;
+}
+
+int pakfire_db_package_filelist(struct pakfire_db* db, PakfireFilelist* filelist,
+ PakfirePackage pkg) {
+ PakfireFilelist fl = NULL;
+ sqlite3_stmt* stmt = NULL;
+ int r = 1;
+
+ // Fetch the package ID
+ uint64_t id = pakfire_package_get_dbid(pkg);
+ if (!id) {
+ ERROR(db->pakfire, "Package did not have an ID\n");
+ return 1;
+ }
+
+ // Create a new filelist
+ r = pakfire_filelist_create(&fl, db->pakfire);
+ if (r) {
+ ERROR(db->pakfire, "Could not create filelist: %m\n");
+ goto ERROR;
+ }
+
+ const char* sql =
+ "SELECT "
+ "path, "
+ "size, "
+ "mode, "
+ "user, "
+ "'group', "
+ "ctime, "
+ "mtime "
+ "FROM files "
+
+ // Select all files that belong to this package
+ "WHERE "
+ "pkg = ? "
+
+ // Filter out any files that are also in a different package (i.e. an update
+ // that has already been installed and this is the cleanup of the obsolete pkg)
+ "AND "
+ "NOT EXISTS ("
+ "SELECT "
+ "1 "
+ "FROM files AS duplicates "
+ "WHERE "
+ "files.path = duplicates.path "
+ "AND "
+ "files.pkg != duplicates.pkg"
+ ") "
+
+ // Return the longest paths first
+ "ORDER BY "
+ "length(path) DESC"
+ ";";
+
+ // Prepare the statement
+ r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
+ if (r) {
+ ERROR(db->pakfire, "Could not prepare SQL statement: %s %s\n",
+ sql, sqlite3_errmsg(db->handle));
+ goto ERROR;
+ }
+
+ // Bind package ID
+ r = sqlite3_bind_int64(stmt, 1, id);
+ if (r) {
+ ERROR(db->pakfire, "Could not bind package ID: %s\n", sqlite3_errmsg(db->handle));
+ goto ERROR;
+ }
+
+ for (;;) {
+ // Execute query
+ r = sqlite3_step(stmt);
+
+ switch (r) {
+ // Retry if the database was busy
+ case SQLITE_BUSY:
+ continue;
+
+ // Read a row
+ case SQLITE_ROW:
+ r = pakfire_db_load_file(db, fl, stmt);
+ if (r)
+ goto ERROR;
+ break;
+
+ // All rows have been processed
+ case SQLITE_DONE:
+ goto END;
+
+ // Go to error in any other cases
+ default:
+ goto ERROR;
+ }
+ }
+
+END:
+ *filelist = pakfire_filelist_ref(fl);
+ r = 0;
+
+ERROR:
+ if (stmt)
+ sqlite3_finalize(stmt);
+ if (fl)
+ pakfire_filelist_unref(fl);
+
+ return r;
+}