[pacman-dev] [PATCH 1/2] libalpm: add ALPM_TRANS_FLAG_NOHOOKS

morganamilo morganamilo at archlinux.org
Sun Jun 13 12:28:15 UTC 2021


---
 lib/libalpm/alpm.h  | 3 ++-
 lib/libalpm/trans.c | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index c4acc062..8dab8c62 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -2721,7 +2721,8 @@ typedef enum _alpm_transflag_t {
 	ALPM_TRANS_FLAG_RECURSE = (1 << 5),
 	/** Modify database but do not commit changes to the filesystem. */
 	ALPM_TRANS_FLAG_DBONLY = (1 << 6),
-	/* (1 << 7) flag can go here */
+	/** Do not run hooks during a transaction */
+	ALPM_TRANS_FLAG_NOHOOKS = (1 << 7),
 	/** Use ALPM_PKG_REASON_DEPEND when installing packages. */
 	ALPM_TRANS_FLAG_ALLDEPS = (1 << 8),
 	/** Only download packages and do not actually install. */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index f22f9bf9..ae5c72ae 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -198,7 +198,8 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
 		}
 	}
 
-	if(_alpm_hook_run(handle, ALPM_HOOK_PRE_TRANSACTION) != 0) {
+	if(!(trans->flags & ALPM_TRANS_FLAG_NOHOOKS) &&
+			_alpm_hook_run(handle, ALPM_HOOK_PRE_TRANSACTION) != 0) {
 		RET_ERR(handle, ALPM_ERR_TRANS_HOOK_FAILED, -1);
 	}
 
@@ -232,7 +233,10 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
 		event.type = ALPM_EVENT_TRANSACTION_DONE;
 		EVENT(handle, (void *)&event);
 		alpm_logaction(handle, ALPM_CALLER_PREFIX, "transaction completed\n");
-		_alpm_hook_run(handle, ALPM_HOOK_POST_TRANSACTION);
+
+		if(!(trans->flags & ALPM_TRANS_FLAG_NOHOOKS)) {
+			_alpm_hook_run(handle, ALPM_HOOK_POST_TRANSACTION);
+		}
 	}
 
 	trans->state = STATE_COMMITED;
-- 
2.32.0


More information about the pacman-dev mailing list