chantra / rpms / rpm

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