]> git.ipfire.org Git - pakfire.git/commitdiff
snapshots: Reload package database after restore
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Mar 2021 11:33:17 +0000 (11:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Mar 2021 11:33:17 +0000 (11:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/snapshot.c

index 7a82daa125a9a5d188513b484bddfda17bf1631a..c6bdecc185eb6ceb96feef3307ed89632e413030 100644 (file)
 
 #include <archive.h>
 
+#include <pakfire/db.h>
 #include <pakfire/file.h>
 #include <pakfire/filelist.h>
 #include <pakfire/logging.h>
 #include <pakfire/private.h>
+#include <pakfire/repo.h>
 #include <pakfire/snapshot.h>
 #include <pakfire/types.h>
 #include <pakfire/util.h>
@@ -198,7 +200,7 @@ ERROR:
        return r;
 }
 
-PAKFIRE_EXPORT int pakfire_snapshot_restore(Pakfire pakfire, FILE* f) {
+static int pakfire_snapshot_extract(Pakfire pakfire, FILE* f) {
        int r = 1;
 
        struct archive* a = archive_read_new();
@@ -275,3 +277,31 @@ ERROR:
 
        return r;
 }
+
+PAKFIRE_EXPORT int pakfire_snapshot_restore(Pakfire pakfire, FILE* f) {
+       struct pakfire_db* db = NULL;
+
+       // Extract the archive
+       int r = pakfire_snapshot_extract(pakfire, f);
+       if (r)
+               return r;
+
+       PakfireRepo repo = pakfire_get_installed_repo(pakfire);
+       if (!repo)
+               goto ERROR;
+
+       // Reload the database
+       r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE);
+       if (r)
+               goto ERROR;
+
+       r = pakfire_db_load(db, repo);
+
+ERROR:
+       if (repo)
+               pakfire_repo_unref(repo);
+       if (db)
+               pakfire_db_unref(db);
+
+       return r;
+}