]> git.ipfire.org Git - pakfire.git/commitdiff
db: Implement fetching the entire filelist
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 13:56:16 +0000 (13:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 13:56:16 +0000 (13:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c
src/libpakfire/include/pakfire/db.h

index 5ba760e58d7762c65c12e48aebc760c27c17e8ab..ae7ebf378bc8edd573ba0599b623b7a4234b6aeb 100644 (file)
@@ -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;
index 59838dd9819af49cf442a6aeb3c30f430791d39b..72084c9d305c60f7dc99adab6d5f0a39fc84652e 100644 (file)
@@ -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);