From: Michael Tremer Date: Fri, 19 Aug 2022 13:56:16 +0000 (+0000) Subject: db: Implement fetching the entire filelist X-Git-Tag: 0.9.28~425 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f310c2615d59ee9ee2556dda356bd54450bd583;p=pakfire.git db: Implement fetching the entire filelist Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index 5ba760e58..ae7ebf378 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -2156,6 +2156,81 @@ ERROR: return r; } +int pakfire_db_filelist(struct pakfire_db* db, struct pakfire_filelist** filelist) { + struct pakfire_filelist* list = NULL; + sqlite3_stmt* stmt = NULL; + int r; + + const char* sql = + "SELECT " + "path, " + "size, " + "mode, " + "user, " + "'group', " + "ctime, " + "mtime " + "FROM files " + "ORDER BY path" + ";"; + + // 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; + } + + // Create a new filelist + r = pakfire_filelist_create(&list, db->pakfire); + if (r) + goto ERROR; + + // Iterate over all rows + 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, list, stmt); + if (r) + goto ERROR; + break; + + // All rows have been processed + case SQLITE_DONE: + r = 0; + goto END; + + // Go to error in any other cases + default: + goto ERROR; + } + } + +END: + // Return the filelist + *filelist = pakfire_filelist_ref(list); + +ERROR: + if (r) + ERROR(db->pakfire, "Could not fetch filelist: %m\n"); + + if (stmt) + sqlite3_finalize(stmt); + if (list) + pakfire_filelist_unref(list); + + return r; +} + int pakfire_db_package_filelist(struct pakfire_db* db, struct pakfire_filelist** filelist, struct pakfire_package* pkg) { struct pakfire_filelist* fl = NULL; diff --git a/src/libpakfire/include/pakfire/db.h b/src/libpakfire/include/pakfire/db.h index 59838dd98..72084c9d3 100644 --- a/src/libpakfire/include/pakfire/db.h +++ b/src/libpakfire/include/pakfire/db.h @@ -56,6 +56,7 @@ int pakfire_db_load(struct pakfire_db* db, struct pakfire_repo* repo); struct pakfire_scriptlet* pakfire_db_get_scriptlet( struct pakfire_db* db, struct pakfire_package* pkg, const char* type); +int pakfire_db_filelist(struct pakfire_db* db, struct pakfire_filelist** filelist); int pakfire_db_package_filelist(struct pakfire_db* db, struct pakfire_filelist** filelist, struct pakfire_package* pkg);