dcavalca / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
3791cf
From 08473f4ad8d79e6d232832c6863b2848f8a41734 Mon Sep 17 00:00:00 2001
3791cf
From: Michal Domonkos <mdomonko@redhat.com>
3791cf
Date: Mon, 7 Dec 2015 17:13:26 +0100
3791cf
Subject: [PATCH] Add RPMCALLBACK_ELEM_PROGRESS callback type
3791cf
3791cf
Currently, there's no callback type that would be issued per each
3791cf
transaction element.  RPMCALLBACK_TRANS_PROGRESS is only issued during
3791cf
the prepare phase but not when packages are actually installed or
3791cf
erased.  Likewise, RPMCALLBACK_INST_ST* and RPMCALLBACK_UNINST_ST* won't
3791cf
be issued if an install or erase operation is skipped for some reason (a
3791cf
script or package upgrade failure).
3791cf
3791cf
Having such a callback would allow the Python API consumers to always
3791cf
know upfront which element is about to be processed, before any other
3791cf
callbacks are issued.  This is important since not every callback type
3791cf
carries enough data about the subject package; while the INST types
3791cf
provide the user object passed to a former addInstall call, the UNINST
3791cf
types only provide the package name (which may not be unique within the
3791cf
transaction set).
3791cf
3791cf
This commit adds such a callback.
3791cf
3791cf
(cherry picked from commit 448db68ceb5be3c7171b7ec0ea908d905792dc2f)
3791cf
---
3791cf
 lib/rpmcallback.h  | 1 +
3791cf
 lib/transaction.c  | 4 ++++
3791cf
 python/rpmmodule.c | 1 +
3791cf
 3 files changed, 6 insertions(+)
3791cf
3791cf
diff --git a/lib/rpmcallback.h b/lib/rpmcallback.h
3791cf
index b3b05c6c1..b6d434c01 100644
3791cf
--- a/lib/rpmcallback.h
3791cf
+++ b/lib/rpmcallback.h
3791cf
@@ -31,6 +31,7 @@ typedef enum rpmCallbackType_e {
3791cf
     RPMCALLBACK_SCRIPT_START	= (1 << 16),
3791cf
     RPMCALLBACK_SCRIPT_STOP	= (1 << 17),
3791cf
     RPMCALLBACK_INST_STOP	= (1 << 18),
3791cf
+    RPMCALLBACK_ELEM_PROGRESS	= (1 << 19),
3791cf
 } rpmCallbackType;
3791cf
 
3791cf
 /**
3791cf
diff --git a/lib/transaction.c b/lib/transaction.c
3791cf
index 45c30b5ba..1cd9ca674 100644
3791cf
--- a/lib/transaction.c
3791cf
+++ b/lib/transaction.c
3791cf
@@ -1410,12 +1410,16 @@ exit:
3791cf
 static int rpmtsProcess(rpmts ts)
3791cf
 {
3791cf
     rpmtsi pi;	rpmte p;
3791cf
+    tsMembers tsmem = rpmtsMembers(ts);
3791cf
     int rc = 0;
3791cf
+    int i = 0;
3791cf
 
3791cf
     pi = rpmtsiInit(ts);
3791cf
     while ((p = rpmtsiNext(pi, 0)) != NULL) {
3791cf
 	int failed;
3791cf
 
3791cf
+	rpmtsNotify(ts, NULL, RPMCALLBACK_ELEM_PROGRESS, i++,
3791cf
+		tsmem->orderCount);
3791cf
 	rpmlog(RPMLOG_DEBUG, "========== +++ %s %s-%s 0x%x\n",
3791cf
 		rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
3791cf
 
3791cf
diff --git a/python/rpmmodule.c b/python/rpmmodule.c
3791cf
index 04285a63f..fc8115d30 100644
3791cf
--- a/python/rpmmodule.c
3791cf
+++ b/python/rpmmodule.c
3791cf
@@ -459,6 +459,7 @@ static int initModule(PyObject *m)
3791cf
     REGISTER_ENUM(RPMCALLBACK_SCRIPT_START);
3791cf
     REGISTER_ENUM(RPMCALLBACK_SCRIPT_STOP);
3791cf
     REGISTER_ENUM(RPMCALLBACK_INST_STOP);
3791cf
+    REGISTER_ENUM(RPMCALLBACK_ELEM_PROGRESS);
3791cf
 
3791cf
     REGISTER_ENUM(RPMPROB_BADARCH);
3791cf
     REGISTER_ENUM(RPMPROB_BADOS);
3791cf
-- 
3791cf
2.13.2
3791cf