chantra / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
3791cf
This patchset consists of following upstream commits:
3791cf
- 1f3164ae6975747e72af383f2d74c27245e6fe36
3791cf
- fd40d58efa0fbff535f273e5ae5c200d43d28aef
3791cf
- bfa76529864b9dfb29258f4dedc3fa9de9c5aeca
3791cf
- 6665503ec6fb6430ecaafb3e318a4730f146efa9
3791cf
- bf856744f2820a1625ef9428284b5788d18103f3
3791cf
- c5200145fa08da884ce2c1ed85941363eeae6407
3791cf
- 80dee39fb1f97ab3927c10bdd13c7c438b5677be
3791cf
3791cf
with some changes to make RPM to compile.
3791cf
3791cf
diff -uNr rpm-4.11.3/doc/rpm.8 rpm-4.11.3.reinstall/doc/rpm.8
3791cf
--- rpm-4.11.3/doc/rpm.8	2017-07-12 16:57:41.711722771 +0200
3791cf
+++ rpm-4.11.3.reinstall/doc/rpm.8	2017-07-12 16:14:26.842680581 +0200
3791cf
@@ -110,7 +110,7 @@
3791cf
 One of the following basic modes must be selected:
3791cf
 \fBQuery\fR,
3791cf
 \fBVerify\fR,
3791cf
-\fBInstall/Upgrade/Freshen\fR,
3791cf
+\fBInstall/Upgrade/Freshen/Reinstall\fR,
3791cf
 \fBUninstall\fR,
3791cf
 \fBSet Owners/Groups\fR,
3791cf
 \fBShow Querytags\fR, and
3791cf
@@ -206,6 +206,13 @@
3791cf
 This will upgrade packages, but only ones for which an earlier version is
3791cf
 installed.
3791cf
 .PP
3791cf
+The general form of an rpm reinstall command is 
3791cf
+.PP
3791cf
+\fBrpm\fR {\fB--reinstall\fR} [\fBinstall-options\fR] \fB\fIPACKAGE_FILE\fB\fR\fI ...\fR
3791cf
+.PP
3791cf
+This reinstalls a previously installed package.
3791cf
+.PP
3791cf
+.PP
3791cf
 .TP
3791cf
 \fB--allfiles\fR
3791cf
 Installs or upgrades all the missingok files in the package,
3791cf
diff -uNr rpm-4.11.3/lib/depends.c rpm-4.11.3.reinstall/lib/depends.c
3791cf
--- rpm-4.11.3/lib/depends.c	2017-07-12 16:57:41.742723041 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/depends.c	2017-07-12 16:14:12.203550634 +0200
3791cf
@@ -54,6 +54,12 @@
3791cf
 #undef HASHTYPE
3791cf
 #undef HTKEYTYPE
3791cf
 
3791cf
+enum addOp_e {
3791cf
+    RPMTE_INSTALL	= 0,
3791cf
+    RPMTE_UPGRADE	= 1,
3791cf
+    RPMTE_REINSTALL	= 2,
3791cf
+};
3791cf
+
3791cf
 /**
3791cf
  * Check for supported payload format in header.
3791cf
  * @param h		header to check
3791cf
@@ -126,7 +132,7 @@
3791cf
 }
3791cf
 
3791cf
 /* Return rpmdb iterator with removals optionally pruned out */
3791cf
-static rpmdbMatchIterator rpmtsPrunedIterator(rpmts ts, rpmDbiTagVal tag,
3791cf
+rpmdbMatchIterator rpmtsPrunedIterator(rpmts ts, rpmDbiTagVal tag,
3791cf
 					      const char * key, int prune)
3791cf
 {
3791cf
     rpmdbMatchIterator mi = rpmtsInitIterator(ts, tag, key, 0);
3791cf
@@ -152,22 +158,29 @@
3791cf
 }
3791cf
 
3791cf
 /* Add erase elements for older packages of same color (if any). */
3791cf
-static int addUpgradeErasures(rpmts ts, rpm_color_t tscolor,
3791cf
+static int addSelfErasures(rpmts ts, rpm_color_t tscolor, int op,
3791cf
 				rpmte p, rpm_color_t hcolor, Header h)
3791cf
 {
3791cf
     Header oh;
3791cf
     rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0);
3791cf
     int rc = 0;
3791cf
+    int cmp;
3791cf
 
3791cf
     while((oh = rpmdbNextIterator(mi)) != NULL) {
3791cf
 	/* Ignore colored packages not in our rainbow. */
3791cf
 	if (skipColor(tscolor, hcolor, headerGetNumber(oh, RPMTAG_HEADERCOLOR)))
3791cf
 	    continue;
3791cf
 
3791cf
-	/* Skip packages that contain identical NEVR. */
3791cf
-	if (rpmVersionCompare(h, oh) == 0)
3791cf
+	cmp = rpmVersionCompare(h, oh);
3791cf
+
3791cf
+	/* On upgrade, skip packages that contain identical NEVR. */
3791cf
+	if ((op == RPMTE_UPGRADE) && (cmp == 0))
3791cf
 	    continue;
3791cf
 
3791cf
+	/* On reinstall, skip packages with differing NEVR. */
3791cf
+	if ((op == RPMTE_REINSTALL) && (cmp != 0))
3791cf
+	    continue;
3791cf
+	
3791cf
 	if (removePackage(ts, oh, p)) {
3791cf
 	    rc = 1;
3791cf
 	    break;
3791cf
@@ -385,8 +398,8 @@
3791cf
     return al;
3791cf
 }
3791cf
 
3791cf
-int rpmtsAddInstallElement(rpmts ts, Header h,
3791cf
-			fnpyKey key, int upgrade, rpmRelocation * relocs)
3791cf
+static int addPackage(rpmts ts, Header h,
3791cf
+		    fnpyKey key, int op, rpmRelocation * relocs)
3791cf
 {
3791cf
     tsMembers tsmem = rpmtsMembers(ts);
3791cf
     rpm_color_t tscolor = rpmtsColor(ts);
3791cf
@@ -403,10 +416,10 @@
3791cf
 
3791cf
     /* Source packages are never "upgraded" */
3791cf
     if (isSource)
3791cf
-	upgrade = 0;
3791cf
+	op = RPMTE_INSTALL;
3791cf
 
3791cf
     /* Do lazy (readonly?) open of rpm database for upgrades. */
3791cf
-    if (upgrade && rpmtsGetRdb(ts) == NULL && rpmtsGetDBMode(ts) != -1) {
3791cf
+    if (op != RPMTE_INSTALL && rpmtsGetRdb(ts) == NULL && rpmtsGetDBMode(ts) != -1) {
3791cf
 	if ((ec = rpmtsOpenDB(ts, rpmtsGetDBMode(ts))) != 0)
3791cf
 	    goto exit;
3791cf
     }
3791cf
@@ -419,7 +432,7 @@
3791cf
 
3791cf
     /* Check binary packages for redundancies in the set */
3791cf
     if (!isSource) {
3791cf
-	oc = findPos(ts, tscolor, p, upgrade);
3791cf
+	oc = findPos(ts, tscolor, p, (op == RPMTE_UPGRADE));
3791cf
 	/* If we're replacing a previously added element, free the old one */
3791cf
 	if (oc >= 0 && oc < tsmem->orderCount) {
3791cf
 	    rpmalDel(tsmem->addedPackages, tsmem->order[oc]);
3791cf
@@ -451,15 +464,33 @@
3791cf
 
3791cf
     /* Add erasure elements for old versions and obsoletions on upgrades */
3791cf
     /* XXX TODO: If either of these fails, we'd need to undo all additions */
3791cf
-    if (upgrade) {
3791cf
-	addUpgradeErasures(ts, tscolor, p, rpmteColor(p), h);
3791cf
+    if (op != RPMTE_INSTALL)
3791cf
+	addSelfErasures(ts, tscolor, op, p, rpmteColor(p), h);
3791cf
+    if (op == RPMTE_UPGRADE)
3791cf
 	addObsoleteErasures(ts, tscolor, p);
3791cf
-    }
3791cf
 
3791cf
 exit:
3791cf
     return ec;
3791cf
 }
3791cf
 
3791cf
+int rpmtsAddInstallElement(rpmts ts, Header h,
3791cf
+			fnpyKey key, int upgrade, rpmRelocation * relocs)
3791cf
+{
3791cf
+    int op = (upgrade == 0) ? RPMTE_INSTALL : RPMTE_UPGRADE;
3791cf
+    if (rpmtsSetupTransactionPlugins(ts) == RPMRC_FAIL)
3791cf
+	return 1;
3791cf
+    return addPackage(ts, h, key, op, relocs);
3791cf
+}
3791cf
+
3791cf
+int rpmtsAddReinstallElement(rpmts ts, Header h, fnpyKey key)
3791cf
+{
3791cf
+    if (rpmtsSetupTransactionPlugins(ts) == RPMRC_FAIL)
3791cf
+	return 1;
3791cf
+    /* TODO: pull relocations from installed package */
3791cf
+    /* TODO: should reinstall of non-installed package fail? */
3791cf
+    return addPackage(ts, h, key, RPMTE_REINSTALL, NULL);
3791cf
+}
3791cf
+
3791cf
 int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset)
3791cf
 {
3791cf
     return removePackage(ts, h, NULL);
3791cf
diff -uNr rpm-4.11.3/lib/poptI.c rpm-4.11.3.reinstall/lib/poptI.c
3791cf
--- rpm-4.11.3/lib/poptI.c	2013-06-07 09:37:21.000000000 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/poptI.c	2017-07-12 16:14:26.842680581 +0200
3791cf
@@ -247,6 +247,10 @@
3791cf
 	&rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
3791cf
 	N_("upgrade package(s)"),
3791cf
 	N_("<packagefile>+") },
3791cf
+ { "reinstall", '\0', POPT_BIT_SET,
3791cf
+	&rpmIArgs.installInterfaceFlags, (INSTALL_REINSTALL|INSTALL_INSTALL),
3791cf
+	N_("reinstall package(s)"),
3791cf
+	N_("<packagefile>+") },
3791cf
 
3791cf
    POPT_TABLEEND
3791cf
 };
3791cf
diff -uNr rpm-4.11.3/lib/rpmcli.h rpm-4.11.3.reinstall/lib/rpmcli.h
3791cf
--- rpm-4.11.3/lib/rpmcli.h	2017-07-12 16:57:41.741723032 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/rpmcli.h	2017-07-12 16:14:26.842680581 +0200
3791cf
@@ -293,7 +293,8 @@
3791cf
     INSTALL_FRESHEN	= (1 << 6),	/*!< from --freshen */
3791cf
     INSTALL_INSTALL	= (1 << 7),	/*!< from --install */
3791cf
     INSTALL_ERASE	= (1 << 8),	/*!< from --erase */
3791cf
-    INSTALL_ALLMATCHES	= (1 << 9)	/*!< from --allmatches */
3791cf
+    INSTALL_ALLMATCHES	= (1 << 9),	/*!< from --allmatches */
3791cf
+    INSTALL_REINSTALL	= (1 << 10),	/*!< from --reinstall */
3791cf
 };
3791cf
 
3791cf
 typedef rpmFlags rpmInstallFlags;
3791cf
@@ -354,7 +355,7 @@
3791cf
 };
3791cf
 
3791cf
 /** \ingroup rpmcli
3791cf
- * Install/upgrade/freshen binary rpm package.
3791cf
+ * Install/upgrade/freshen/reinstall binary rpm package.
3791cf
  * @param ts		transaction set
3791cf
  * @param ia		mode flags and parameters
3791cf
  * @param fileArgv	array of package file names (NULL terminated)
3791cf
diff -uNr rpm-4.11.3/lib/rpminstall.c rpm-4.11.3.reinstall/lib/rpminstall.c
3791cf
--- rpm-4.11.3/lib/rpminstall.c	2014-09-05 13:48:07.000000000 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/rpminstall.c	2017-07-12 16:14:26.843680590 +0200
3791cf
@@ -552,7 +552,10 @@
3791cf
 	        continue;
3791cf
 	    }
3791cf
 
3791cf
-	rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName,
3791cf
+	if (ia->installInterfaceFlags & INSTALL_REINSTALL)
3791cf
+	    rc = rpmtsAddReinstallElement(ts, h, (fnpyKey)fileName);
3791cf
+	else
3791cf
+	    rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName,
3791cf
 			(ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
3791cf
 			relocations);
3791cf
 
3791cf
diff -uNr rpm-4.11.3/lib/rpmts.h rpm-4.11.3.reinstall/lib/rpmts.h
3791cf
--- rpm-4.11.3/lib/rpmts.h	2017-07-12 16:57:41.710722762 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/rpmts.h	2017-07-12 16:14:12.203550634 +0200
3791cf
@@ -544,6 +544,16 @@
3791cf
 		rpmRelocation * relocs);
3791cf
 
3791cf
 /** \ingroup rpmts
3791cf
+ * Add package to be reinstalled to transaction set.
3791cf
+ *
3791cf
+ * @param ts		transaction set
3791cf
+ * @param h		header
3791cf
+ * @param key		package retrieval key (e.g. file name)
3791cf
+ * @return		0 on success
3791cf
+ */
3791cf
+int rpmtsAddReinstallElement(rpmts ts, Header h, const fnpyKey key);
3791cf
+
3791cf
+/** \ingroup rpmts
3791cf
  * Add package to be erased to transaction set.
3791cf
  * @param ts		transaction set
3791cf
  * @param h		header
3791cf
diff -uNr rpm-4.11.3/lib/rpmts_internal.h rpm-4.11.3.reinstall/lib/rpmts_internal.h
3791cf
--- rpm-4.11.3/lib/rpmts_internal.h	2014-06-04 11:25:23.000000000 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/rpmts_internal.h	2017-07-12 16:44:18.613959252 +0200
3791cf
@@ -86,6 +86,11 @@
3791cf
 RPM_GNUC_INTERNAL
3791cf
 tsMembers rpmtsMembers(rpmts ts);
3791cf
 
3791cf
+/* Return rpmdb iterator with removals optionally pruned out */
3791cf
+RPM_GNUC_INTERNAL
3791cf
+rpmdbMatchIterator rpmtsPrunedIterator(rpmts ts, rpmDbiTagVal tag,
3791cf
+					      const char * key, int prune);
3791cf
+
3791cf
 RPM_GNUC_INTERNAL
3791cf
 rpmal rpmtsCreateAl(rpmts ts, rpmElementTypes types);
3791cf
 
3791cf
@@ -118,6 +123,9 @@
3791cf
  */
3791cf
 void rpmtsSELabelFini(rpmts ts, int close_status);
3791cf
 
3791cf
+RPM_GNUC_INTERNAL
3791cf
+rpmRC rpmtsSetupTransactionPlugins(rpmts ts);
3791cf
+
3791cf
 #ifdef __cplusplus
3791cf
 }
3791cf
 #endif
3791cf
diff -uNr rpm-4.11.3/lib/transaction.c rpm-4.11.3.reinstall/lib/transaction.c
3791cf
--- rpm-4.11.3/lib/transaction.c	2017-07-12 16:57:41.747723085 +0200
3791cf
+++ rpm-4.11.3.reinstall/lib/transaction.c	2017-07-12 16:43:59.563741144 +0200
3791cf
@@ -1138,7 +1138,7 @@
3791cf
 	if (!(probFilter & RPMPROB_FILTER_REPLACEPKG)) {
3791cf
 	    Header h;
3791cf
 	    rpmdbMatchIterator mi;
3791cf
-	    mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0);
3791cf
+	    mi = rpmtsPrunedIterator(ts, RPMDBI_NAME, rpmteN(p), 1);
3791cf
 	    rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p));
3791cf
 	    rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p));
3791cf
 	    rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p));
3791cf
@@ -1444,7 +1444,7 @@
3791cf
     return rc;
3791cf
 }
3791cf
 
3791cf
-static rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
3791cf
+rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
3791cf
 {
3791cf
     rpmRC rc = RPMRC_OK;
3791cf
     ARGV_t files = NULL;
3791cf
diff -uNr rpm-4.11.3/python/rpm/transaction.py rpm-4.11.3.reinstall/python/rpm/transaction.py
3791cf
--- rpm-4.11.3/python/rpm/transaction.py	2014-02-05 14:04:02.000000000 +0100
3791cf
+++ rpm-4.11.3.reinstall/python/rpm/transaction.py	2017-07-12 16:14:22.573642686 +0200
3791cf
@@ -50,7 +50,7 @@
3791cf
         else:
3791cf
             return tuple(keys)
3791cf
 
3791cf
-    def addInstall(self, item, key, how="u"):
3791cf
+    def _f2hdr(self, item):
3791cf
         if isinstance(item, _string_types):
3791cf
             f = open(item)
3791cf
             header = self.hdrFromFdno(f)
3791cf
@@ -59,6 +59,10 @@
3791cf
             header = item
3791cf
         else:
3791cf
             header = self.hdrFromFdno(item)
3791cf
+        return header
3791cf
+
3791cf
+    def addInstall(self, item, key, how="u"):
3791cf
+        header = self._f2hdr(item)
3791cf
 
3791cf
         if not how in ['u', 'i']:
3791cf
             raise ValueError('how argument must be "u" or "i"')
3791cf
@@ -67,6 +71,12 @@
3791cf
         if not TransactionSetCore.addInstall(self, header, key, upgrade):
3791cf
             raise rpm.error("adding package to transaction failed")
3791cf
 
3791cf
+    def addReinstall(self, item, key):
3791cf
+        header = self._f2hdr(item)
3791cf
+
3791cf
+        if not TransactionSetCore.addReinstall(self, header, key):
3791cf
+            raise rpm.error("adding package to transaction failed")
3791cf
+
3791cf
     def addErase(self, item):
3791cf
         hdrs = []
3791cf
         if isinstance(item, rpm.hdr):
3791cf
diff -uNr rpm-4.11.3/python/rpmts-py.c rpm-4.11.3.reinstall/python/rpmts-py.c
3791cf
--- rpm-4.11.3/python/rpmts-py.c	2017-07-12 16:57:41.741723032 +0200
3791cf
+++ rpm-4.11.3.reinstall/python/rpmts-py.c	2017-07-12 16:14:18.800609194 +0200
3791cf
@@ -190,6 +190,24 @@
3791cf
 }
3791cf
 
3791cf
 static PyObject *
3791cf
+rpmts_AddReinstall(rpmtsObject * s, PyObject * args)
3791cf
+{
3791cf
+    Header h = NULL;
3791cf
+    PyObject * key;
3791cf
+    int rc;
3791cf
+
3791cf
+    if (!PyArg_ParseTuple(args, "O&O:AddReinstall", 
3791cf
+			  hdrFromPyObject, &h, &key))
3791cf
+	return NULL;
3791cf
+
3791cf
+    rc = rpmtsAddReinstallElement(s->ts, h, key);
3791cf
+    if (key && rc == 0) {
3791cf
+	PyList_Append(s->keyList, key);
3791cf
+    }
3791cf
+    return PyBool_FromLong((rc == 0));
3791cf
+}
3791cf
+
3791cf
+static PyObject *
3791cf
 rpmts_AddErase(rpmtsObject * s, PyObject * args)
3791cf
 {
3791cf
     Header h;
3791cf
@@ -693,6 +711,8 @@
3791cf
 static struct PyMethodDef rpmts_methods[] = {
3791cf
  {"addInstall",	(PyCFunction) rpmts_AddInstall,	METH_VARARGS,
3791cf
 	NULL },
3791cf
+ {"addReinstall",	(PyCFunction) rpmts_AddReinstall,	METH_VARARGS,
3791cf
+	NULL },
3791cf
  {"addErase",	(PyCFunction) rpmts_AddErase,	METH_VARARGS|METH_KEYWORDS,
3791cf
 	NULL },
3791cf
  {"check",	(PyCFunction) rpmts_Check,	METH_VARARGS|METH_KEYWORDS,
3791cf
diff -uNr rpm-4.11.3/rpmqv.c rpm-4.11.3.reinstall/rpmqv.c
3791cf
--- rpm-4.11.3/rpmqv.c	2012-11-07 13:55:24.000000000 +0100
3791cf
+++ rpm-4.11.3.reinstall/rpmqv.c	2017-07-12 16:14:26.843680590 +0200
3791cf
@@ -135,7 +135,8 @@
3791cf
 #ifdef	IAM_RPMEIU
3791cf
   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
3791cf
     {	int iflags = (ia->installInterfaceFlags &
3791cf
-		(INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
3791cf
+			(INSTALL_UPGRADE|INSTALL_FRESHEN|
3791cf
+			 INSTALL_INSTALL|INSTALL_REINSTALL));
3791cf
 	int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
3791cf
 
3791cf
 	if (iflags & eflags)