summaryrefslogtreecommitdiff
path: root/rpmdb.c
diff options
context:
space:
mode:
authorwangbiao <biao716.wang@samsung.com>2023-11-16 18:17:42 +0900
committerwangbiao <biao716.wang@samsung.com>2023-11-16 18:17:42 +0900
commitc30d127e8780dc678168ee121b9f2eeb1a8aaafa (patch)
treecdc9ddc3123edd5741e5151f3076c9bfc9535916 /rpmdb.c
parent258ff2bdb80c458b743417c427f66fa5f27bf7c5 (diff)
downloadlibrpm-tizen-c30d127e8780dc678168ee121b9f2eeb1a8aaafa.tar.gz
librpm-tizen-c30d127e8780dc678168ee121b9f2eeb1a8aaafa.tar.bz2
librpm-tizen-c30d127e8780dc678168ee121b9f2eeb1a8aaafa.zip
Upgrade version to 4.14tizen/4.14.1.1.tizen20230628
Change-Id: I21bf1a3a7c25cbec43022202cf2e5865b603a309 Signed-off-by: wangbiao <biao716.wang@samsung.com>
Diffstat (limited to 'rpmdb.c')
-rw-r--r--rpmdb.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/rpmdb.c b/rpmdb.c
index 7223fdf28..25c088da9 100644
--- a/rpmdb.c
+++ b/rpmdb.c
@@ -2,17 +2,16 @@
#include <popt.h>
#include <rpm/rpmcli.h>
+#include <rpm/rpmdb.h>
#include "cliutils.h"
#include "debug.h"
-#if !defined(__GLIBC__) && !defined(__APPLE__)
-char ** environ = NULL;
-#endif
-
enum modes {
MODE_INITDB = (1 << 0),
MODE_REBUILDDB = (1 << 1),
MODE_VERIFYDB = (1 << 2),
+ MODE_EXPORTDB = (1 << 3),
+ MODE_IMPORTDB = (1 << 4),
};
static int mode = 0;
@@ -25,6 +24,12 @@ static struct poptOption dbOptsTable[] = {
NULL},
{ "verifydb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR|POPT_ARGFLAG_DOC_HIDDEN),
&mode, MODE_VERIFYDB, N_("verify database files"), NULL},
+ { "exportdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_EXPORTDB,
+ N_("export database to stdout header list"),
+ NULL},
+ { "importdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTDB,
+ N_("import database from stdin header list"),
+ NULL},
POPT_TABLEEND
};
@@ -39,12 +44,57 @@ static struct poptOption optionsTable[] = {
POPT_TABLEEND
};
+static int exportDB(rpmts ts)
+{
+ FD_t fd = fdDup(STDOUT_FILENO);
+ rpmtxn txn = rpmtxnBegin(ts, RPMTXN_READ);
+ int rc = 0;
+
+ if (txn && fd) {
+ Header h;
+ rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
+ while ((h = rpmdbNextIterator(mi))) {
+ rc += headerWrite(fd, h, HEADER_MAGIC_YES);
+ }
+ rpmdbFreeIterator(mi);
+ } else {
+ rc = -1;
+ }
+ Fclose(fd);
+ rpmtxnEnd(txn);
+ return rc;
+}
+
+/* XXX: only allow this on empty db? */
+static int importDB(rpmts ts)
+{
+ FD_t fd = fdDup(STDIN_FILENO);
+ rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE);
+ int rc = 0;
+
+ if (txn && fd) {
+ Header h;
+ while ((h = headerRead(fd, HEADER_MAGIC_YES))) {
+ rc += rpmtsImportHeader(txn, h, 0);
+ }
+ } else {
+ rc = -1;
+ }
+ rpmtxnEnd(txn);
+ Fclose(fd);
+ return rc;
+}
+
int main(int argc, char *argv[])
{
int ec = EXIT_FAILURE;
- poptContext optCon = rpmcliInit(argc, argv, optionsTable);
+ poptContext optCon = NULL;
rpmts ts = NULL;
-
+
+ xsetprogname(argv[0]); /* Portability call -- see system.h */
+
+ optCon = rpmcliInit(argc, argv, optionsTable);
+
if (argc < 2 || poptPeekArg(optCon)) {
printUsage(optCon, stderr, 0);
goto exit;
@@ -66,6 +116,12 @@ int main(int argc, char *argv[])
case MODE_VERIFYDB:
ec = rpmtsVerifyDB(ts);
break;
+ case MODE_EXPORTDB:
+ ec = exportDB(ts);
+ break;
+ case MODE_IMPORTDB:
+ ec = importDB(ts);
+ break;
default:
argerror(_("only one major mode may be specified"));
}