[pacman-dev] [PATCH 1/2] libalpm: add ALPM_TRANS_FLAG_NOHOOKS
--- 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
--dbonly is meant to only touch the database and not the actual system. However hooks still run which can leave files in place or run commands you may not want. The hooks being run also means `fakeroot pacman -S --dbpath test/ foo --dbonly` fails because alpm tries to chroot for hooks which requires real root. --- src/pacman/pacman.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 7e810127..f94fd2ea 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -633,6 +633,7 @@ static int parsearg_trans(int opt) case OP_DBONLY: config->flags |= ALPM_TRANS_FLAG_DBONLY; config->flags |= ALPM_TRANS_FLAG_NOSCRIPTLET; + config->flags |= ALPM_TRANS_FLAG_NOHOOKS; break; case OP_NOPROGRESSBAR: config->noprogressbar = 1; -- 2.32.0
On 13/6/21 10:28 pm, morganamilo wrote:
--- 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;
Ack
On 13/6/21 10:28 pm, morganamilo wrote:
--dbonly is meant to only touch the database and not the actual system. However hooks still run which can leave files in place or run commands you may not want.
The hooks being run also means `fakeroot pacman -S --dbpath test/ foo --dbonly` fails because alpm tries to chroot for hooks which requires real root. --- src/pacman/pacman.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 7e810127..f94fd2ea 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -633,6 +633,7 @@ static int parsearg_trans(int opt) case OP_DBONLY: config->flags |= ALPM_TRANS_FLAG_DBONLY; config->flags |= ALPM_TRANS_FLAG_NOSCRIPTLET; + config->flags |= ALPM_TRANS_FLAG_NOHOOKS; break; case OP_NOPROGRESSBAR: config->noprogressbar = 1;
OK
participants (2)
-
Allan McRae
-
morganamilo