[pacman-dev] [PATCH] Notify of removed package required as optdepend

Allan McRae allan at archlinux.org
Sat Aug 11 03:19:00 EDT 2012


When a package is being removed, provide a notification (via a callback)
if any local package requires it as an optdepend.

Signed-off-by: Allan McRae <allan at archlinux.org>
---

I am going through the optdepends patchset submitted by Benedikt Morbach
back in November [1] and adjusting/rewriting/... the patches that only add
some more informational messages.

[1] (https://mailman.archlinux.org/pipermail/pacman-dev/2011-November/014772.html)

Here is an example of the output this patch gives:

allan at mugen /home/arch/code/pacman (optdep)
> sudo ./src/pacman/pacman -R tk
checking dependencies...
:: git optionally requires tk: gitk and git gui
:: python optionally requires tk: for tkinter
:: python2 optionally requires tk: for IDLE
:: r optionally requires tk: tcl/tk interface

Packages (1): tk-8.5.12-1

Total Removed Size:     5.21 MiB

Do you want to remove these packages? [Y/n] n

allan at mugen /home/arch/code/pacman (optdep)
> sudo ./src/pacman/pacman -R tk r git
checking dependencies...
:: python optionally requires tk: for tkinter
:: python2 optionally requires tk: for IDLE

Packages (3): git-1.7.11.4-1  r-2.15.1-2  tk-8.5.12-1

Total Removed Size:     73.41 MiB

Do you want to remove these packages? [Y/n] n


 lib/libalpm/alpm.h    |  5 ++++-
 lib/libalpm/remove.c  | 29 +++++++++++++++++++++++++++++
 src/pacman/callback.c |  4 ++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ac1145b..f8928b9 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -351,7 +351,10 @@ typedef enum _alpm_event_t {
 	/** Disk space usage will be computed for a package */
 	ALPM_EVENT_DISKSPACE_START,
 	/** Disk space usage was computed for a package */
-	ALPM_EVENT_DISKSPACE_DONE
+	ALPM_EVENT_DISKSPACE_DONE,
+	/** An optdepend for another package is being removed
+	 * The requiring package and its dependency are passed to the callback */
+	ALPM_EVENT_OPTDEP_REQUIRED
 } alpm_event_t;
 
 /** Event callback */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 4c54992..80c847e 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -158,6 +158,32 @@ static void remove_prepare_keep_needed(alpm_handle_t *handle, alpm_list_t *lp)
 }
 
 /**
+ * @brief Send a callback for any optdepend being removed.
+ *
+ * @param handle the context handle
+ * @param lp list of packages to be removed
+ */
+static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *lp)
+{
+	alpm_list_t *i;
+
+	for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = alpm_list_next(i)) {
+		alpm_pkg_t *pkg = i->data;
+		alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg);
+
+		if(optdeps && !_alpm_pkg_find(lp, pkg->name)) {
+			alpm_list_t *j;
+			for(j = optdeps; j; j = alpm_list_next(j)) {
+				alpm_depend_t *optdep = j->data;
+				if(_alpm_pkg_find(lp, optdep->name)) {
+					EVENT(handle, ALPM_EVENT_OPTDEP_REQUIRED, pkg, optdep);
+				}
+			}
+		}
+	}
+}
+
+/**
  * @brief Transaction preparation for remove actions.
  *
  * This functions takes a pointer to a alpm_list_t which will be
@@ -228,6 +254,9 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
 		}
 	}
 
+	/* Note packages being removed that are optdepends for installed packages */
+	remove_notify_needed_optdepends(handle, trans->remove);
+
 	if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
 		EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL);
 	}
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 01c6b61..a51aa4b 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -239,6 +239,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
 				printf(_("checking available disk space...\n"));
 			}
 			break;
+		case ALPM_EVENT_OPTDEP_REQUIRED:
+			printf(_(":: %s optionally requires %s\n"), alpm_pkg_get_name(data1),
+				alpm_dep_compute_string(data2));
+			break;
 		/* all the simple done events, with fallthrough for each */
 		case ALPM_EVENT_FILECONFLICTS_DONE:
 		case ALPM_EVENT_CHECKDEPS_DONE:
-- 
1.7.11.4



More information about the pacman-dev mailing list