From: Michael Tremer Date: Wed, 24 Mar 2021 11:33:17 +0000 (+0000) Subject: snapshots: Reload package database after restore X-Git-Tag: 0.9.28~1285^2~477 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb4762c6944560f99b94ca3bde4e40dd690d6121;p=pakfire.git snapshots: Reload package database after restore Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/snapshot.c b/src/libpakfire/snapshot.c index 7a82daa12..c6bdecc18 100644 --- a/src/libpakfire/snapshot.c +++ b/src/libpakfire/snapshot.c @@ -24,10 +24,12 @@ #include +#include #include #include #include #include +#include #include #include #include @@ -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; +}