teknoraver / rpms / rpm

Forked from rpms/rpm 3 months ago
Clone

Blame SOURCES/rpm-4.11.x-reinstall.patch

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