[pacman-dev] [PATCH 0/8] Events
The first three patches are just small changes, then goes the update to the different structs instead of the two void* arguments, and making the log stuff into an event as well. Then adding events about creation of the pac* files as originally discussed; And I've also included a few new events, as mentioned before, that could be useful to frontends, even though pacman just ignores them (for now). A couple of other things : - Andrew mentioned FS#37711, which could be addressed now that those (creation of pacnew/pacorig files) are fully handled by pacman, but for now I've simply let those as warnings, much like they were before. Since the color issue has been fixed (i.e. such messages didn't have colors applied when they were delayed due to a progress operation) I'm not sure if anything else is really needed anyways. - I don't think addressing FS#36504 was right. This was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. I think this might have been a mistake: I guess it all depends on when you consider the operation to be completed, once pacman's extraction reached 100%, or after the scriptlet have run. I feel the later is right, since they are part of the process of installing/upgrading/etc a package; Of course, you may disagree. Either way, the current situation is wrong, because right now ALPM does : 1. add log message about the operation being done 2. run scriptlet 3. signal frontend (via event) that operation is done IOW if a frontend was to actually use the event to present its output to the user, it wouldn't match the order in the log, which is wrong. This was done because pacman ignores that event, only showing the progress of the extraction, and thus people feel that it goes 1. install done; then 2. scriptlet. In fact, pacman doesn't really ignore the event, and uses it to show (new) optdep. Should this be done before or after the scriptlet? One could also ask, when using --noprogressbar pacman doesn't say anything at the end of the operation (save for optdep), imagine it would: should it be before or after the scriptlet? As I said, I think the logging should be moved after the scriptlet have run, as this is when the operation is really done. If you were to disagree though, then the event should be moved before the scriptlet run, to keep consistency between the frontend and the log (which is broken ATM), but this just feels wrong to me, since then a frontend would consider a package upgrade/etc done, when in fact the scriptlet have yet to run (and produce new output relating to the operation supposedly done). Olivier Brunel (8): pacman: Make sure delayed warnings/errors are shown the same Rename ALPM_EVENT_OPTDEP_REQUIRED to _OPTDEP_REMOVED alpm: Rename a variable for clarity Update the event callback Remove log_cb, add ALPM_EVENT_LOG instead Add events on pacnew/pacsave/pacorig file creation Add events ALPM_EVENT_RETRIEVE_{DONE,FAILED} Add events _PKGDOWNLOAD_{START,DONE,FAILED} lib/libalpm/add.c | 86 +++++++++++------ lib/libalpm/alpm.h | 248 ++++++++++++++++++++++++++++++++---------------- lib/libalpm/be_sync.c | 6 +- lib/libalpm/handle.c | 13 --- lib/libalpm/handle.h | 5 +- lib/libalpm/log.c | 14 ++- lib/libalpm/remove.c | 32 +++++-- lib/libalpm/sync.c | 94 +++++++++++++----- lib/libalpm/util.c | 6 +- src/pacman/callback.c | 181 ++++++++++++++++++++++++----------- src/pacman/callback.h | 6 +- src/pacman/conf.c | 1 - src/pacman/util.c | 19 +++- src/pacman/util.h | 1 + src/util/cleanupdelta.c | 14 +-- src/util/testdb.c | 14 +-- src/util/testpkg.c | 14 +-- 17 files changed, 510 insertions(+), 244 deletions(-) -- 1.8.4.2
When delayed until after a progress operation, they wouldn't be in colors, and be sent to stdout instead of stderr. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- src/pacman/callback.c | 2 +- src/pacman/util.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index a181fa5..c412f6f 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -529,7 +529,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, alpm_list_t *i = NULL; on_progress = 0; for(i = output; i; i = i->next) { - fputs((const char *)i->data, stdout); + fputs((const char *)i->data, stderr); } fflush(stdout); FREELIST(output); diff --git a/src/pacman/util.c b/src/pacman/util.c index 23eea98..4877cc3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1593,10 +1593,12 @@ int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_li /* print a prefix to the message */ switch(level) { case ALPM_LOG_ERROR: - pm_asprintf(string, _("error: %s"), msg); + pm_asprintf(string, "%s%s%s%s", config->colstr.err, _("error: "), + config->colstr.nocolor, msg); break; case ALPM_LOG_WARNING: - pm_asprintf(string, _("warning: %s"), msg); + pm_asprintf(string, "%s%s%s%s", config->colstr.warn, _("warning: "), + config->colstr.nocolor, msg); break; case ALPM_LOG_DEBUG: pm_asprintf(string, "debug: %s", msg); -- 1.8.4.2
On 03/12/13 06:45, Olivier Brunel wrote:
When delayed until after a progress operation, they wouldn't be in colors, and be sent to stdout instead of stderr.
Signed-off-by: Olivier Brunel <jjk@jjacky.com> ---
I had submitted a patch to deal with the color a couple of weeks beforehand [1] which has now been pushed to master. [1] https://mailman.archlinux.org/pipermail/pacman-dev/2013-November/018241.html So that part is no longer needed.
src/pacman/callback.c | 2 +- src/pacman/util.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index a181fa5..c412f6f 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -529,7 +529,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, alpm_list_t *i = NULL; on_progress = 0; for(i = output; i; i = i->next) { - fputs((const char *)i->data, stdout); + fputs((const char *)i->data, stderr); } fflush(stdout);
I guess we want the fflush(stdout) to happen before the outputting to stderr here, and probably an fflush(stderr) afterwards.
FREELIST(output); diff --git a/src/pacman/util.c b/src/pacman/util.c index 23eea98..4877cc3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1593,10 +1593,12 @@ int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_li /* print a prefix to the message */ switch(level) { case ALPM_LOG_ERROR: - pm_asprintf(string, _("error: %s"), msg); + pm_asprintf(string, "%s%s%s%s", config->colstr.err, _("error: "), + config->colstr.nocolor, msg); break; case ALPM_LOG_WARNING: - pm_asprintf(string, _("warning: %s"), msg); + pm_asprintf(string, "%s%s%s%s", config->colstr.warn, _("warning: "), + config->colstr.nocolor, msg); break; case ALPM_LOG_DEBUG: pm_asprintf(string, "debug: %s", msg);
Because this event is triggered when an optdepend for another package is being removed. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 2 +- lib/libalpm/remove.c | 2 +- src/pacman/callback.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e9b0feb..c6d9064 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -377,7 +377,7 @@ typedef enum _alpm_event_t { 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_OPTDEP_REMOVED, /** A configured repository database is missing */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 9417a61..8884495 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,7 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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); + EVENT(handle, ALPM_EVENT_OPTDEP_REMOVED, pkg, optdep); } } } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index c412f6f..e80a071 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -247,7 +247,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("checking available disk space...\n")); } break; - case ALPM_EVENT_OPTDEP_REQUIRED: + case ALPM_EVENT_OPTDEP_REMOVED: colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), alpm_dep_compute_string(data2)); break; -- 1.8.4.2
On 03/12/13 06:45, Olivier Brunel wrote:
Because this event is triggered when an optdepend for another package is being removed.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I am not convinced by this. The event happens when the dependencies are being checked before removing a package. pacman current just prints a warning, but another frontend might want to query the user before removing the package. So at that stage, the optdep is required and not removed.
--- lib/libalpm/alpm.h | 2 +- lib/libalpm/remove.c | 2 +- src/pacman/callback.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e9b0feb..c6d9064 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -377,7 +377,7 @@ typedef enum _alpm_event_t { 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_OPTDEP_REMOVED, /** A configured repository database is missing */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 9417a61..8884495 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,7 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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); + EVENT(handle, ALPM_EVENT_OPTDEP_REMOVED, pkg, optdep); } } } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index c412f6f..e80a071 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -247,7 +247,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("checking available disk space...\n")); } break; - case ALPM_EVENT_OPTDEP_REQUIRED: + case ALPM_EVENT_OPTDEP_REMOVED: colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), alpm_dep_compute_string(data2)); break;
On 12/15/13 13:00, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Because this event is triggered when an optdepend for another package is being removed.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I am not convinced by this. The event happens when the dependencies are being checked before removing a package. pacman current just prints a warning, but another frontend might want to query the user before removing the package. So at that stage, the optdep is required and not removed.
Well, I think it's wrong to say the optdep is required. Not just because there's no real sense of "requirement" (as in, it's optional), but more importantly because the only thing is that a package that will be removed happens to be listed as optdep of another (installed) package. It doesn't mean that this was the reason the package was installed, or that the user ever made any use of the package as such optdep. Indicating that there's a notion of requirement here feels just wrong to me. And the name ALPM_EVENT_OPTDEP_REQUIRED implies (to me) that this is what the event is about, the requirement part. When going over this I got confused about what it meant, and this is why I suggested a renaming. To go back to your example, I don't see an problem with the following: - ALPM emits an event OPTDEP_REMOVED to indicate an optdep is (going to be) removed. - the frontend then queries the user, to confirm this removal (as this is a removal we're talking about here). To be pedantic, we might want to say ALPM_EVENT_OPTDEP_REMOVAL_PENDING or something, which would be more precise/correct, but also quite long. For the sake or being short, I just went with REMOVED, which I think remains valid. REQUIRED OTOH does not. I'm not opposed to using something other than REMOVED, but IMHO it should be renamed, as REQUIRED is wrong/confusing (it doesn't even convey anything regarding the removal, which again is really what this (event) is about, the (pending) *removal* of an optdep). -j
--- lib/libalpm/alpm.h | 2 +- lib/libalpm/remove.c | 2 +- src/pacman/callback.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e9b0feb..c6d9064 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -377,7 +377,7 @@ typedef enum _alpm_event_t { 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_OPTDEP_REMOVED, /** A configured repository database is missing */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 9417a61..8884495 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,7 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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); + EVENT(handle, ALPM_EVENT_OPTDEP_REMOVED, pkg, optdep); } } } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index c412f6f..e80a071 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -247,7 +247,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("checking available disk space...\n")); } break; - case ALPM_EVENT_OPTDEP_REQUIRED: + case ALPM_EVENT_OPTDEP_REMOVED: colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), alpm_dep_compute_string(data2)); break;
On 12/15/13 at 03:43pm, Olivier Brunel wrote:
On 12/15/13 13:00, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Because this event is triggered when an optdepend for another package is being removed.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I am not convinced by this. The event happens when the dependencies are being checked before removing a package. pacman current just prints a warning, but another frontend might want to query the user before removing the package. So at that stage, the optdep is required and not removed.
Well, I think it's wrong to say the optdep is required. Not just because there's no real sense of "requirement" (as in, it's optional), but more importantly because the only thing is that a package that will be removed happens to be listed as optdep of another (installed) package.
It doesn't mean that this was the reason the package was installed, or that the user ever made any use of the package as such optdep. Indicating that there's a notion of requirement here feels just wrong to me. And the name ALPM_EVENT_OPTDEP_REQUIRED implies (to me) that this is what the event is about, the requirement part. When going over this I got confused about what it meant, and this is why I suggested a renaming.
To go back to your example, I don't see an problem with the following: - ALPM emits an event OPTDEP_REMOVED to indicate an optdep is (going to be) removed. - the frontend then queries the user, to confirm this removal (as this is a removal we're talking about here).
To be pedantic, we might want to say ALPM_EVENT_OPTDEP_REMOVAL_PENDING or something, which would be more precise/correct, but also quite long. For the sake or being short, I just went with REMOVED, which I think remains valid. REQUIRED OTOH does not.
I'm not opposed to using something other than REMOVED, but IMHO it should be renamed, as REQUIRED is wrong/confusing (it doesn't even convey anything regarding the removal, which again is really what this (event) is about, the (pending) *removal* of an optdep).
-j
Just to be clear, transactions should not be altered once trans_prepare has started. The front-end can only display a warning or abort the entire transaction (and it can only even do that after trans_prepare is finished). If we want front-ends to be able to choose not to remove the individual package, this needs to be a question so that the optdep is never added to the transaction in the first place, not an event. Of course, this would only apply to packages added to the transaction by alpm. Personally, I think we should just emit a generic package-added-to-transaction event and let the front-end do checks and display whatever warnings it wants and/or abort the transaction. apg
On 16/12/13 00:43, Olivier Brunel wrote:
On 12/15/13 13:00, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Because this event is triggered when an optdepend for another package is being removed.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I am not convinced by this. The event happens when the dependencies are being checked before removing a package. pacman current just prints a warning, but another frontend might want to query the user before removing the package. So at that stage, the optdep is required and not removed.
Well, I think it's wrong to say the optdep is required. Not just because there's no real sense of "requirement" (as in, it's optional), but more importantly because the only thing is that a package that will be removed happens to be listed as optdep of another (installed) package.
It doesn't mean that this was the reason the package was installed, or that the user ever made any use of the package as such optdep. Indicating that there's a notion of requirement here feels just wrong to me. And the name ALPM_EVENT_OPTDEP_REQUIRED implies (to me) that this is what the event is about, the requirement part. When going over this I got confused about what it meant, and this is why I suggested a renaming.
To go back to your example, I don't see an problem with the following: - ALPM emits an event OPTDEP_REMOVED to indicate an optdep is (going to be) removed. - the frontend then queries the user, to confirm this removal (as this is a removal we're talking about here).
To be pedantic, we might want to say ALPM_EVENT_OPTDEP_REMOVAL_PENDING or something, which would be more precise/correct, but also quite long. For the sake or being short, I just went with REMOVED, which I think remains valid. REQUIRED OTOH does not.
I'm not opposed to using something other than REMOVED, but IMHO it should be renamed, as REQUIRED is wrong/confusing (it doesn't even convey anything regarding the removal, which again is really what this (event) is about, the (pending) *removal* of an optdep).
I'll accept ALPM_EVENT_OPTDEP_REMOVAL
Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 214e78e..c7e5b5d 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -459,7 +459,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_pkg_t *oldpkg = NULL; alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; - alpm_progress_t event = ALPM_PROGRESS_ADD_START; + alpm_progress_t progress = ALPM_PROGRESS_ADD_START; alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; const char *log_msg = "adding"; const char *pkgfile; @@ -472,17 +472,17 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, int cmp = _alpm_pkg_compare_versions(newpkg, local); if(cmp < 0) { log_msg = "downgrading"; - event = ALPM_PROGRESS_DOWNGRADE_START; + progress = ALPM_PROGRESS_DOWNGRADE_START; start = ALPM_EVENT_DOWNGRADE_START; done = ALPM_EVENT_DOWNGRADE_DONE; } else if(cmp == 0) { log_msg = "reinstalling"; - event = ALPM_PROGRESS_REINSTALL_START; + progress = ALPM_PROGRESS_REINSTALL_START; start = ALPM_EVENT_REINSTALL_START; done = ALPM_EVENT_REINSTALL_DONE; } else { log_msg = "upgrading"; - event = ALPM_PROGRESS_UPGRADE_START; + progress = ALPM_PROGRESS_UPGRADE_START; start = ALPM_EVENT_UPGRADE_START; done = ALPM_EVENT_UPGRADE_DONE; } @@ -572,7 +572,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, } /* call PROGRESS once with 0 percent, as we sort-of skip that here */ - PROGRESS(handle, event, newpkg->name, 0, pkg_count, pkg_current); + PROGRESS(handle, progress, newpkg->name, 0, pkg_count, pkg_current); for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) { int percent; @@ -590,7 +590,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, percent = 0; } - PROGRESS(handle, event, newpkg->name, percent, pkg_count, pkg_current); + PROGRESS(handle, progress, newpkg->name, percent, pkg_count, pkg_current); /* extract the next file from the archive */ errors += extract_single_file(handle, archive, entry, newpkg, oldpkg); @@ -647,7 +647,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, newpkg->name); } - PROGRESS(handle, event, newpkg->name, 100, pkg_count, pkg_current); + PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current); switch(done) { case ALPM_EVENT_ADD_DONE: -- 1.8.4.2
On 03/12/13 06:45, Olivier Brunel wrote:
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
Ack. I extended the commit message to note it is for _future_ clarity that this rename is being done for.
--- lib/libalpm/add.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 214e78e..c7e5b5d 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -459,7 +459,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_pkg_t *oldpkg = NULL; alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; - alpm_progress_t event = ALPM_PROGRESS_ADD_START; + alpm_progress_t progress = ALPM_PROGRESS_ADD_START; alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; const char *log_msg = "adding"; const char *pkgfile; @@ -472,17 +472,17 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, int cmp = _alpm_pkg_compare_versions(newpkg, local); if(cmp < 0) { log_msg = "downgrading"; - event = ALPM_PROGRESS_DOWNGRADE_START; + progress = ALPM_PROGRESS_DOWNGRADE_START; start = ALPM_EVENT_DOWNGRADE_START; done = ALPM_EVENT_DOWNGRADE_DONE; } else if(cmp == 0) { log_msg = "reinstalling"; - event = ALPM_PROGRESS_REINSTALL_START; + progress = ALPM_PROGRESS_REINSTALL_START; start = ALPM_EVENT_REINSTALL_START; done = ALPM_EVENT_REINSTALL_DONE; } else { log_msg = "upgrading"; - event = ALPM_PROGRESS_UPGRADE_START; + progress = ALPM_PROGRESS_UPGRADE_START; start = ALPM_EVENT_UPGRADE_START; done = ALPM_EVENT_UPGRADE_DONE; } @@ -572,7 +572,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, }
/* call PROGRESS once with 0 percent, as we sort-of skip that here */ - PROGRESS(handle, event, newpkg->name, 0, pkg_count, pkg_current); + PROGRESS(handle, progress, newpkg->name, 0, pkg_count, pkg_current);
for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) { int percent; @@ -590,7 +590,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, percent = 0; }
- PROGRESS(handle, event, newpkg->name, percent, pkg_count, pkg_current); + PROGRESS(handle, progress, newpkg->name, percent, pkg_count, pkg_current);
/* extract the next file from the archive */ errors += extract_single_file(handle, archive, entry, newpkg, oldpkg); @@ -647,7 +647,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, newpkg->name); }
- PROGRESS(handle, event, newpkg->name, 100, pkg_count, pkg_current); + PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current);
switch(done) { case ALPM_EVENT_ADD_DONE:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered. With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 31 ++++++----- lib/libalpm/alpm.h | 150 +++++++++++++++++++++++++++++--------------------- lib/libalpm/be_sync.c | 6 +- lib/libalpm/handle.h | 4 +- lib/libalpm/remove.c | 25 +++++++-- lib/libalpm/sync.c | 82 +++++++++++++++++++-------- lib/libalpm/util.c | 6 +- src/pacman/callback.c | 87 ++++++++++++++++------------- src/pacman/callback.h | 2 +- 9 files changed, 244 insertions(+), 149 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index c7e5b5d..3067df5 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -460,7 +460,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; alpm_progress_t progress = ALPM_PROGRESS_ADD_START; - alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; + alpm_event_update_t event; const char *log_msg = "adding"; const char *pkgfile; @@ -473,18 +473,15 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, if(cmp < 0) { log_msg = "downgrading"; progress = ALPM_PROGRESS_DOWNGRADE_START; - start = ALPM_EVENT_DOWNGRADE_START; - done = ALPM_EVENT_DOWNGRADE_DONE; + event.operation = ALPM_OPERATION_DOWNGRADE; } else if(cmp == 0) { log_msg = "reinstalling"; progress = ALPM_PROGRESS_REINSTALL_START; - start = ALPM_EVENT_REINSTALL_START; - done = ALPM_EVENT_REINSTALL_DONE; + event.operation = ALPM_OPERATION_REINSTALL; } else { log_msg = "upgrading"; progress = ALPM_PROGRESS_UPGRADE_START; - start = ALPM_EVENT_UPGRADE_START; - done = ALPM_EVENT_UPGRADE_DONE; + event.operation = ALPM_OPERATION_UPGRADE; } is_upgrade = 1; @@ -496,9 +493,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, /* copy over the install reason */ newpkg->reason = alpm_pkg_get_reason(local); + } else { + event.operation = ALPM_OPERATION_INSTALL; } - EVENT(handle, start, newpkg, local); + event.type = ALPM_EVENT_UPDATE_START; + event.oldpkg = oldpkg; + event.newpkg = newpkg; + EVENT(handle, &event); pkgfile = newpkg->origin_data.file; @@ -649,20 +651,20 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current); - switch(done) { - case ALPM_EVENT_ADD_DONE: + switch(event.operation) { + case ALPM_OPERATION_INSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "installed %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_DOWNGRADE_DONE: + case ALPM_OPERATION_DOWNGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "downgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; - case ALPM_EVENT_REINSTALL_DONE: + case ALPM_OPERATION_REINSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "reinstalled %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_UPGRADE_DONE: + case ALPM_OPERATION_UPGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "upgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; @@ -682,7 +684,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, free(scriptlet); } - EVENT(handle, done, newpkg, oldpkg); + event.type = ALPM_EVENT_UPDATE_DONE; + EVENT(handle, &event); cleanup: _alpm_pkg_free(oldpkg); diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index c6d9064..eba9375 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -275,10 +275,9 @@ int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4))); /** - * Events. - * NULL parameters are passed to in all events unless specified otherwise. + * Type of events. */ -typedef enum _alpm_event_t { +typedef enum _alpm_event_type_t { /** Dependencies will be computed for a package. */ ALPM_EVENT_CHECKDEPS_START = 1, /** Dependencies were computed for a package. */ @@ -295,49 +294,12 @@ typedef enum _alpm_event_t { ALPM_EVENT_INTERCONFLICTS_START, /** Inter-conflicts were checked for target package. */ ALPM_EVENT_INTERCONFLICTS_DONE, - /** Package will be installed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_ADD_START, - /** Package was installed. - * A pointer to the new package is passed to the callback. - */ - ALPM_EVENT_ADD_DONE, - /** Package will be removed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_REMOVE_START, - /** Package was removed. - * A pointer to the removed package is passed to the callback. - */ - ALPM_EVENT_REMOVE_DONE, - /** Package will be upgraded. - * A pointer to the upgraded package is passed to the callback. - */ - ALPM_EVENT_UPGRADE_START, - /** Package was upgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_UPGRADE_DONE, - /** Package will be downgraded. - * A pointer to the downgraded package is passed to the callback. - */ - ALPM_EVENT_DOWNGRADE_START, - /** Package was downgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_DOWNGRADE_DONE, - /** Package will be reinstalled. - * A pointer to the reinstalled package is passed to the callback. - */ - ALPM_EVENT_REINSTALL_START, - /** Package was reinstalled. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_REINSTALL_DONE, + /** Package will be installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_update_t for arguments. */ + ALPM_EVENT_UPDATE_START, + /** Package was installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_update_t for arguments. */ + ALPM_EVENT_UPDATE_DONE, /** Target package's integrity will be checked. */ ALPM_EVENT_INTEGRITY_START, /** Target package's integrity was checked. */ @@ -354,31 +316,27 @@ typedef enum _alpm_event_t { ALPM_EVENT_DELTA_PATCHES_START, /** Deltas were applied to packages. */ ALPM_EVENT_DELTA_PATCHES_DONE, - /** Delta patch will be applied to target package. - * The filename of the package and the filename of the patch is passed to the - * callback. - */ + /** Delta patch will be applied to target package; See + * alpm_event_delta_patch_t for arguments.. */ ALPM_EVENT_DELTA_PATCH_START, /** Delta patch was applied to target package. */ ALPM_EVENT_DELTA_PATCH_DONE, /** Delta patch failed to apply to target package. */ ALPM_EVENT_DELTA_PATCH_FAILED, - /** Scriptlet has printed information. - * A line of text is passed to the callback. - */ + /** Scriptlet has printed information; See alpm_event_scriptlet_info_t for + * arguments. */ ALPM_EVENT_SCRIPTLET_INFO, - /** Files will be downloaded from a repository. - * The repository's tree name is passed to the callback. - */ + /** Files will be downloaded from a repository. */ ALPM_EVENT_RETRIEVE_START, - /** Disk space usage will be computed for a package */ + /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, - /** Disk space usage was computed for a package */ + /** Disk space usage was computed for a package. */ ALPM_EVENT_DISKSPACE_DONE, - /** An optdepend for another package is being removed - * The requiring package and its dependency are passed to the callback */ + /** An optdepend for another package is being removed; See + * alpm_event_optdep_removed_t for arguments. */ ALPM_EVENT_OPTDEP_REMOVED, - /** A configured repository database is missing */ + /** A configured repository database is missing; See + * alpm_event_database_missing_t for arguments. */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ ALPM_EVENT_KEYRING_START, @@ -388,10 +346,76 @@ typedef enum _alpm_event_t { ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE +} alpm_event_type_t; + +/** Events. + * This is a generic struct this is passed to the callback, that allows the + * frontend to know which type of event was triggered. It is then possible to + * typecast the pointer to the right structure, in order to access + * event-specific data. */ +typedef struct _alpm_event_t { + /** Type of event. */ + alpm_event_type_t type; } alpm_event_t; -/** Event callback */ -typedef void (*alpm_cb_event)(alpm_event_t, void *, void *); +typedef enum _alpm_pkg_operation_t { + /** Package (to be) installed. (No oldpkg) */ + ALPM_OPERATION_INSTALL = 1, + /** Package (to be) upgraded */ + ALPM_OPERATION_UPGRADE, + /** Package (to be) re-installed. */ + ALPM_OPERATION_REINSTALL, + /** Package (to be) downgraded. */ + ALPM_OPERATION_DOWNGRADE, + /** Package (to be) removed. (No newpkg) */ + ALPM_OPERATION_REMOVE +} alpm_operation_t; + +typedef struct _alpm_event_update_t { + /** Type of event. */ + alpm_event_type_t type; + /** Type of operation. */ + alpm_operation_t operation; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New package. */ + alpm_pkg_t *newpkg; +} alpm_event_update_t; + +typedef struct _alpm_event_optdep_removed_t { + /** Type of event. */ + alpm_event_type_t type; + /** Package with the optdep. */ + alpm_pkg_t *pkg; + /** Optdep being removed. */ + alpm_depend_t *optdep; +} alpm_event_optdep_removed_t; + +typedef struct _alpm_event_delta_patch_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the file. */ + const char *pkg_filename; + /** Name of the patch. */ + const char *patch_filename; +} alpm_event_delta_patch_t; + +typedef struct _alpm_event_scriptlet_info_t { + /** Type of event. */ + alpm_event_type_t type; + /** Line of scriptlet output. */ + const char *line; +} alpm_event_scriptlet_info_t; + +typedef struct _alpm_event_database_missing_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the database. */ + const char *dbname; +} alpm_event_database_missing_t; + +/** Event callback. */ +typedef void (*alpm_cb_event)(alpm_event_t *); /** * Questions. diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 123d953..3f3d54f 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -89,9 +89,13 @@ static int sync_db_validate(alpm_db_t *db) /* we can skip any validation if the database doesn't exist */ if(_alpm_access(db->handle, NULL, dbpath, R_OK) != 0 && errno == ENOENT) { + alpm_event_database_missing_t event = { + .type = ALPM_EVENT_DATABASE_MISSING, + .dbname = db->treename + }; db->status &= ~DB_STATUS_EXISTS; db->status |= DB_STATUS_MISSING; - EVENT(db->handle, ALPM_EVENT_DATABASE_MISSING, db->treename, NULL); + EVENT(db->handle, &event); goto valid; } db->status |= DB_STATUS_EXISTS; diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 4126e1a..4275d13 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -31,10 +31,10 @@ #include <curl/curl.h> #endif -#define EVENT(h, e, d1, d2) \ +#define EVENT(h, e) \ do { \ if((h)->eventcb) { \ - (h)->eventcb(e, d1, d2); \ + (h)->eventcb((alpm_event_t *) (e)); \ } \ } while(0) #define QUESTION(h, q, d1, d2, d3, r) \ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 8884495..32d71ab 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,12 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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_REMOVED, pkg, optdep); + alpm_event_optdep_removed_t event = { + .type = ALPM_EVENT_OPTDEP_REMOVED, + .pkg = pkg, + .optdep = optdep + }; + EVENT(handle, &event); } } } @@ -203,6 +208,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_t *lp; alpm_trans_t *trans = handle->trans; alpm_db_t *db = handle->db_local; + alpm_event_t event; if((trans->flags & ALPM_TRANS_FLAG_RECURSE) && !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) { @@ -214,7 +220,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) } if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1); @@ -261,7 +268,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) remove_notify_needed_optdepends(handle, trans->remove); if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_DONE; + EVENT(handle, &event); } return 0; @@ -663,12 +671,18 @@ int _alpm_remove_single_package(alpm_handle_t *handle, { const char *pkgname = oldpkg->name; const char *pkgver = oldpkg->version; + alpm_event_update_t event = { + .type = ALPM_EVENT_UPDATE_START, + .operation = ALPM_OPERATION_REMOVE, + .oldpkg = oldpkg, + .newpkg = NULL + }; if(newpkg) { _alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n", pkgname, pkgver); } else { - EVENT(handle, ALPM_EVENT_REMOVE_START, oldpkg, NULL); + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n", pkgname, pkgver); @@ -702,7 +716,8 @@ int _alpm_remove_single_package(alpm_handle_t *handle, } if(!newpkg) { - EVENT(handle, ALPM_EVENT_REMOVE_DONE, oldpkg, NULL); + event.type = ALPM_EVENT_UPDATE_DONE; + EVENT(handle, &event); } /* remove the package from the database */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 551f926..c79000c 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -369,6 +369,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) size_t from_sync = 0; int ret = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event; if(data) { *data = NULL; @@ -398,7 +399,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) /* Build up list by repeatedly resolving each transaction package */ /* Resolve targets dependencies */ - EVENT(handle, ALPM_EVENT_RESOLVEDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n"); /* build remove list for resolvedeps */ @@ -474,12 +476,14 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_free(trans->add); trans->add = resolved; - EVENT(handle, ALPM_EVENT_RESOLVEDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_DONE; + EVENT(handle, &event); } if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) { /* check for inter-conflicts and whatnot */ - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n"); @@ -590,7 +594,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) goto cleanup; } } - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_DONE; + EVENT(handle, &event); alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free); alpm_list_free(deps); } @@ -679,6 +684,7 @@ static int apply_deltas(alpm_handle_t *handle) int deltas_found = 0, ret = 0; const char *cachedir = _alpm_filecache_setup(handle); alpm_trans_t *trans = handle->trans; + alpm_event_delta_patch_t event; for(i = trans->add; i; i = i->next) { alpm_pkg_t *spkg = i->data; @@ -692,7 +698,8 @@ static int apply_deltas(alpm_handle_t *handle) if(!deltas_found) { /* only show this if we actually have deltas to apply, and it is before * the very first one */ - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_START; + EVENT(handle, &event); deltas_found = 1; } @@ -726,11 +733,15 @@ static int apply_deltas(alpm_handle_t *handle) _alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command); - EVENT(handle, ALPM_EVENT_DELTA_PATCH_START, d->to, d->delta); + event.type = ALPM_EVENT_DELTA_PATCH_START; + event.pkg_filename = d->to; + event.patch_filename = d->delta; + EVENT(handle, &event); int retval = system(command); if(retval == 0) { - EVENT(handle, ALPM_EVENT_DELTA_PATCH_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_DONE; + EVENT(handle, &event); /* delete the delta file */ unlink(delta); @@ -748,7 +759,8 @@ static int apply_deltas(alpm_handle_t *handle) if(retval != 0) { /* one delta failed for this package, cancel the remaining ones */ - EVENT(handle, ALPM_EVENT_DELTA_PATCH_FAILED, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_FAILED; + EVENT(handle, &event); handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED; ret = 1; break; @@ -756,7 +768,8 @@ static int apply_deltas(alpm_handle_t *handle) } } if(deltas_found) { - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_DONE; + EVENT(handle, &event); } return ret; @@ -785,13 +798,15 @@ static int prompt_to_delete(alpm_handle_t *handle, const char *filepath, static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) { alpm_list_t *i, *errors = NULL; + alpm_event_t event; if(!deltas) { return 0; } /* Check integrity of deltas */ - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_START; + EVENT(handle, &event); for(i = deltas; i; i = i->next) { alpm_delta_t *d = i->data; char *filepath = _alpm_filecache_find(handle, d->delta); @@ -802,7 +817,8 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) FREE(filepath); } } - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_DONE; + EVENT(handle, &event); if(errors) { for(i = errors; i; i = i->next) { @@ -908,6 +924,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) const char *cachedir; alpm_list_t *i, *files = NULL; int errors = 0; + alpm_event_t event; cachedir = _alpm_filecache_setup(handle); handle->trans->state = STATE_DOWNLOADING; @@ -955,7 +972,8 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) } } - EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL); + event.type = ALPM_EVENT_RETRIEVE_START; + EVENT(handle, &event); for(i = files; i; i = i->next) { if(download_single_file(handle, i->data, cachedir) == -1) { errors++; @@ -989,8 +1007,10 @@ static int check_keyring(alpm_handle_t *handle) { size_t current = 0, numtargs; alpm_list_t *i, *errors = NULL; + alpm_event_t event; - EVENT(handle, ALPM_EVENT_KEYRING_START, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_START; + EVENT(handle, &event); numtargs = alpm_list_count(handle->trans->add); @@ -1033,10 +1053,12 @@ static int check_keyring(alpm_handle_t *handle) PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", 100, numtargs, current); - EVENT(handle, ALPM_EVENT_KEYRING_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_DONE; + EVENT(handle, &event); if(errors) { - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_START, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_START; + EVENT(handle, &event); int fail = 0; alpm_list_t *k; for(k = errors; k; k = k->next) { @@ -1045,7 +1067,8 @@ static int check_keyring(alpm_handle_t *handle) fail = 1; } } - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_DONE; + EVENT(handle, &event); if(fail) { _alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n")); return -1; @@ -1070,9 +1093,11 @@ static int check_validity(alpm_handle_t *handle, size_t current = 0; uint64_t current_bytes = 0; alpm_list_t *i, *errors = NULL; + alpm_event_t event; /* Check integrity of packages */ - EVENT(handle, ALPM_EVENT_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_START; + EVENT(handle, &event); for(i = handle->trans->add; i; i = i->next, current++) { struct validity v = { i->data, NULL, NULL, 0, 0, 0 }; @@ -1104,7 +1129,8 @@ static int check_validity(alpm_handle_t *handle, PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_DONE; + EVENT(handle, &event); if(errors) { for(i = errors; i; i = i->next) { @@ -1143,9 +1169,11 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, size_t current = 0, current_bytes = 0; int errors = 0; alpm_list_t *i; + alpm_event_t event; /* load packages from disk now that they are known-valid */ - EVENT(handle, ALPM_EVENT_LOAD_START, NULL, NULL); + event.type = ALPM_EVENT_LOAD_START; + EVENT(handle, &event); for(i = handle->trans->add; i; i = i->next, current++) { alpm_pkg_t *spkg = i->data; @@ -1186,7 +1214,8 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_LOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_LOAD_DONE; + EVENT(handle, &event); if(errors) { if(!handle->pm_errno) { @@ -1204,6 +1233,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) size_t total = 0; uint64_t total_bytes = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event; if(download_files(handle, &deltas)) { alpm_list_free(deltas); @@ -1262,7 +1292,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) /* fileconflict check */ if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_FILECONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n"); alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle, @@ -1277,12 +1308,14 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1); } - EVENT(handle, ALPM_EVENT_FILECONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_DONE; + EVENT(handle, &event); } /* check available disk space */ if(handle->checkspace && !(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_DISKSPACE_START, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n"); if(_alpm_check_diskspace(handle) == -1) { @@ -1290,7 +1323,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) return -1; } - EVENT(handle, ALPM_EVENT_DISKSPACE_DONE, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_DONE; + EVENT(handle, &event); } /* remove conflicting and to-be-replaced packages */ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index f9fdb01..4a9ea75 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -571,10 +571,14 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]) } else { while(!feof(pipe_file)) { char line[PATH_MAX]; + alpm_event_scriptlet_info_t event = { + .type = ALPM_EVENT_SCRIPTLET_INFO, + .line = line + }; if(fgets(line, PATH_MAX, pipe_file) == NULL) break; alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line); - EVENT(handle, ALPM_EVENT_SCRIPTLET_INFO, line, NULL); + EVENT(handle, &event); } fclose(pipe_file); } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index e80a071..040c2bd 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -149,12 +149,12 @@ static void fill_progress(const int bar_percent, const int disp_percent, } /* callback to handle messages/notifications from libalpm transactions */ -void cb_event(alpm_event_t event, void *data1, void *data2) +void cb_event(alpm_event_t *event) { if(config->print) { return; } - switch(event) { + switch(event->type) { case ALPM_EVENT_CHECKDEPS_START: printf(_("checking dependencies...\n")); break; @@ -169,38 +169,43 @@ void cb_event(alpm_event_t event, void *data1, void *data2) case ALPM_EVENT_INTERCONFLICTS_START: printf(_("looking for conflicting packages...\n")); break; - case ALPM_EVENT_ADD_START: - if(config->noprogressbar) { - printf(_("installing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_ADD_DONE: - display_optdepends(data1); - break; - case ALPM_EVENT_REMOVE_START: + case ALPM_EVENT_UPDATE_START: if(config->noprogressbar) { - printf(_("removing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_START: - if(config->noprogressbar) { - printf(_("upgrading %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_DOWNGRADE_START: - if(config->noprogressbar) { - printf(_("downgrading %s...\n"), alpm_pkg_get_name(data1)); + alpm_event_update_t *e = (alpm_event_update_t *) event; + switch(e->operation) { + case ALPM_OPERATION_INSTALL: + printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_UPGRADE: + printf(_("upgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_REINSTALL: + printf(_("reinstalling %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_DOWNGRADE: + printf(_("downgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_REMOVE: + printf(_("removing %s...\n"), alpm_pkg_get_name(e->oldpkg)); + break; + } } break; - case ALPM_EVENT_DOWNGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_REINSTALL_START: - if(config->noprogressbar) { - printf(_("reinstalling %s...\n"), alpm_pkg_get_name(data1)); + case ALPM_EVENT_UPDATE_DONE: + { + alpm_event_update_t *e = (alpm_event_update_t *) event; + switch(e->operation) { + case ALPM_OPERATION_INSTALL: + display_optdepends(e->newpkg); + break; + case ALPM_OPERATION_UPGRADE: + case ALPM_OPERATION_DOWNGRADE: + display_new_optdepends(e->oldpkg, e->newpkg); + break; + case ALPM_OPERATION_REINSTALL: + case ALPM_OPERATION_REMOVE: + break; + } } break; case ALPM_EVENT_INTEGRITY_START: @@ -228,7 +233,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("applying deltas...\n")); break; case ALPM_EVENT_DELTA_PATCH_START: - printf(_("generating %s with %s... "), (char *)data1, (char *)data2); + { + alpm_event_delta_patch_t *e = (alpm_event_delta_patch_t *) event; + printf(_("generating %s with %s... "), e->pkg_filename, e->patch_filename); + } break; case ALPM_EVENT_DELTA_PATCH_DONE: printf(_("success!\n")); @@ -237,7 +245,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("failed.\n")); break; case ALPM_EVENT_SCRIPTLET_INFO: - fputs((const char *)data1, stdout); + fputs(((alpm_event_scriptlet_info_t *) event)->line, stdout); break; case ALPM_EVENT_RETRIEVE_START: colon_printf(_("Retrieving packages ...\n")); @@ -248,18 +256,21 @@ void cb_event(alpm_event_t event, void *data1, void *data2) } break; case ALPM_EVENT_OPTDEP_REMOVED: - colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), - alpm_dep_compute_string(data2)); + { + alpm_event_optdep_removed_t *e = (alpm_event_optdep_removed_t *) event; + colon_printf(_("%s optionally requires %s\n"), + alpm_pkg_get_name(e->pkg), + alpm_dep_compute_string(e->optdep)); + } break; case ALPM_EVENT_DATABASE_MISSING: if(!config->op_s_sync) { pm_printf(ALPM_LOG_WARNING, - "database file for '%s' does not exist\n", (char *)data1); + "database file for '%s' does not exist\n", + ((alpm_event_database_missing_t *) event)->dbname); } break; /* all the simple done events, with fallthrough for each */ - case ALPM_EVENT_REINSTALL_DONE: - case ALPM_EVENT_REMOVE_DONE: case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: case ALPM_EVENT_RESOLVEDEPS_DONE: diff --git a/src/pacman/callback.h b/src/pacman/callback.h index a291fc7..b19b952 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -25,7 +25,7 @@ #include <alpm.h> /* callback to handle messages/notifications from libalpm */ -void cb_event(alpm_event_t event, void *data1, void *data2); +void cb_event(alpm_event_t *event); /* callback to handle questions from libalpm (yes/no) */ void cb_question(alpm_question_t event, void *data1, void *data2, -- 1.8.4.2
On 03/12/13 06:45, Olivier Brunel wrote:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered.
With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I have given couple of suggestions below for naming that I think makes things clearer. Also a query regarding the delta event struct. Otherwise, this looks good.
--- lib/libalpm/add.c | 31 ++++++----- lib/libalpm/alpm.h | 150 +++++++++++++++++++++++++++++--------------------- lib/libalpm/be_sync.c | 6 +- lib/libalpm/handle.h | 4 +- lib/libalpm/remove.c | 25 +++++++-- lib/libalpm/sync.c | 82 +++++++++++++++++++-------- lib/libalpm/util.c | 6 +- src/pacman/callback.c | 87 ++++++++++++++++------------- src/pacman/callback.h | 2 +- 9 files changed, 244 insertions(+), 149 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index c7e5b5d..3067df5 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -460,7 +460,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; alpm_progress_t progress = ALPM_PROGRESS_ADD_START; - alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; + alpm_event_update_t event; const char *log_msg = "adding"; const char *pkgfile;
@@ -473,18 +473,15 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, if(cmp < 0) { log_msg = "downgrading"; progress = ALPM_PROGRESS_DOWNGRADE_START; - start = ALPM_EVENT_DOWNGRADE_START; - done = ALPM_EVENT_DOWNGRADE_DONE; + event.operation = ALPM_OPERATION_DOWNGRADE; } else if(cmp == 0) { log_msg = "reinstalling"; progress = ALPM_PROGRESS_REINSTALL_START; - start = ALPM_EVENT_REINSTALL_START; - done = ALPM_EVENT_REINSTALL_DONE; + event.operation = ALPM_OPERATION_REINSTALL; } else { log_msg = "upgrading"; progress = ALPM_PROGRESS_UPGRADE_START; - start = ALPM_EVENT_UPGRADE_START; - done = ALPM_EVENT_UPGRADE_DONE; + event.operation = ALPM_OPERATION_UPGRADE; } is_upgrade = 1;
@@ -496,9 +493,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
/* copy over the install reason */ newpkg->reason = alpm_pkg_get_reason(local); + } else { + event.operation = ALPM_OPERATION_INSTALL; }
- EVENT(handle, start, newpkg, local); + event.type = ALPM_EVENT_UPDATE_START; + event.oldpkg = oldpkg; + event.newpkg = newpkg; + EVENT(handle, &event);
pkgfile = newpkg->origin_data.file;
@@ -649,20 +651,20 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current);
- switch(done) { - case ALPM_EVENT_ADD_DONE: + switch(event.operation) { + case ALPM_OPERATION_INSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "installed %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_DOWNGRADE_DONE: + case ALPM_OPERATION_DOWNGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "downgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; - case ALPM_EVENT_REINSTALL_DONE: + case ALPM_OPERATION_REINSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "reinstalled %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_UPGRADE_DONE: + case ALPM_OPERATION_UPGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "upgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; @@ -682,7 +684,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, free(scriptlet); }
- EVENT(handle, done, newpkg, oldpkg); + event.type = ALPM_EVENT_UPDATE_DONE; + EVENT(handle, &event);
cleanup: _alpm_pkg_free(oldpkg); diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index c6d9064..eba9375 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -275,10 +275,9 @@ int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
/** - * Events. - * NULL parameters are passed to in all events unless specified otherwise. + * Type of events. */ -typedef enum _alpm_event_t { +typedef enum _alpm_event_type_t { /** Dependencies will be computed for a package. */ ALPM_EVENT_CHECKDEPS_START = 1, /** Dependencies were computed for a package. */ @@ -295,49 +294,12 @@ typedef enum _alpm_event_t { ALPM_EVENT_INTERCONFLICTS_START, /** Inter-conflicts were checked for target package. */ ALPM_EVENT_INTERCONFLICTS_DONE, - /** Package will be installed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_ADD_START, - /** Package was installed. - * A pointer to the new package is passed to the callback. - */ - ALPM_EVENT_ADD_DONE, - /** Package will be removed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_REMOVE_START, - /** Package was removed. - * A pointer to the removed package is passed to the callback. - */ - ALPM_EVENT_REMOVE_DONE, - /** Package will be upgraded. - * A pointer to the upgraded package is passed to the callback. - */ - ALPM_EVENT_UPGRADE_START, - /** Package was upgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_UPGRADE_DONE, - /** Package will be downgraded. - * A pointer to the downgraded package is passed to the callback. - */ - ALPM_EVENT_DOWNGRADE_START, - /** Package was downgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_DOWNGRADE_DONE, - /** Package will be reinstalled. - * A pointer to the reinstalled package is passed to the callback. - */ - ALPM_EVENT_REINSTALL_START, - /** Package was reinstalled. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_REINSTALL_DONE, + /** Package will be installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_update_t for arguments. */ + ALPM_EVENT_UPDATE_START,
UPDATE does not sound right to me here. How about ALPM_EVENT_PACKAGE_OPERATION_START?
+ /** Package was installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_update_t for arguments. */ + ALPM_EVENT_UPDATE_DONE, /** Target package's integrity will be checked. */ ALPM_EVENT_INTEGRITY_START, /** Target package's integrity was checked. */ @@ -354,31 +316,27 @@ typedef enum _alpm_event_t { ALPM_EVENT_DELTA_PATCHES_START, /** Deltas were applied to packages. */ ALPM_EVENT_DELTA_PATCHES_DONE, - /** Delta patch will be applied to target package. - * The filename of the package and the filename of the patch is passed to the - * callback. - */ + /** Delta patch will be applied to target package; See + * alpm_event_delta_patch_t for arguments.. */ ALPM_EVENT_DELTA_PATCH_START, /** Delta patch was applied to target package. */ ALPM_EVENT_DELTA_PATCH_DONE, /** Delta patch failed to apply to target package. */ ALPM_EVENT_DELTA_PATCH_FAILED, - /** Scriptlet has printed information. - * A line of text is passed to the callback. - */ + /** Scriptlet has printed information; See alpm_event_scriptlet_info_t for + * arguments. */ ALPM_EVENT_SCRIPTLET_INFO, - /** Files will be downloaded from a repository. - * The repository's tree name is passed to the callback. - */ + /** Files will be downloaded from a repository. */ ALPM_EVENT_RETRIEVE_START, - /** Disk space usage will be computed for a package */ + /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, - /** Disk space usage was computed for a package */ + /** Disk space usage was computed for a package. */ ALPM_EVENT_DISKSPACE_DONE, - /** An optdepend for another package is being removed - * The requiring package and its dependency are passed to the callback */ + /** An optdepend for another package is being removed; See + * alpm_event_optdep_removed_t for arguments. */ ALPM_EVENT_OPTDEP_REMOVED, - /** A configured repository database is missing */ + /** A configured repository database is missing; See + * alpm_event_database_missing_t for arguments. */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ ALPM_EVENT_KEYRING_START, @@ -388,10 +346,76 @@ typedef enum _alpm_event_t { ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE +} alpm_event_type_t; + +/** Events. + * This is a generic struct this is passed to the callback, that allows the + * frontend to know which type of event was triggered. It is then possible to + * typecast the pointer to the right structure, in order to access + * event-specific data. */ +typedef struct _alpm_event_t { + /** Type of event. */ + alpm_event_type_t type; } alpm_event_t;
-/** Event callback */ -typedef void (*alpm_cb_event)(alpm_event_t, void *, void *); +typedef enum _alpm_pkg_operation_t {
_alpm_package_operation_t
+ /** Package (to be) installed. (No oldpkg) */ + ALPM_OPERATION_INSTALL = 1,
ALPM_PACKAGE_INSTALL
+ /** Package (to be) upgraded */ + ALPM_OPERATION_UPGRADE, + /** Package (to be) re-installed. */ + ALPM_OPERATION_REINSTALL, + /** Package (to be) downgraded. */ + ALPM_OPERATION_DOWNGRADE, + /** Package (to be) removed. (No newpkg) */ + ALPM_OPERATION_REMOVE +} alpm_operation_t;
alpm_package_operation_t
+typedef struct _alpm_event_update_t {
_alpm_event_package_operation_t
+ /** Type of event. */ + alpm_event_type_t type; + /** Type of operation. */ + alpm_operation_t operation; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New package. */ + alpm_pkg_t *newpkg; +} alpm_event_update_t; + +typedef struct _alpm_event_optdep_removed_t { + /** Type of event. */ + alpm_event_type_t type; + /** Package with the optdep. */ + alpm_pkg_t *pkg; + /** Optdep being removed. */ + alpm_depend_t *optdep; +} alpm_event_optdep_removed_t; + +typedef struct _alpm_event_delta_patch_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the file. */ + const char *pkg_filename; + /** Name of the patch. */ + const char *patch_filename;
Any reason to not just pass the alpm_delta_t* here?
+} alpm_event_delta_patch_t; + +typedef struct _alpm_event_scriptlet_info_t { + /** Type of event. */ + alpm_event_type_t type; + /** Line of scriptlet output. */ + const char *line; +} alpm_event_scriptlet_info_t; + +typedef struct _alpm_event_database_missing_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the database. */ + const char *dbname; +} alpm_event_database_missing_t; + +/** Event callback. */ +typedef void (*alpm_cb_event)(alpm_event_t *);
/** * Questions. diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 123d953..3f3d54f 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -89,9 +89,13 @@ static int sync_db_validate(alpm_db_t *db)
/* we can skip any validation if the database doesn't exist */ if(_alpm_access(db->handle, NULL, dbpath, R_OK) != 0 && errno == ENOENT) { + alpm_event_database_missing_t event = { + .type = ALPM_EVENT_DATABASE_MISSING, + .dbname = db->treename + }; db->status &= ~DB_STATUS_EXISTS; db->status |= DB_STATUS_MISSING; - EVENT(db->handle, ALPM_EVENT_DATABASE_MISSING, db->treename, NULL); + EVENT(db->handle, &event); goto valid; } db->status |= DB_STATUS_EXISTS; diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 4126e1a..4275d13 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -31,10 +31,10 @@ #include <curl/curl.h> #endif
-#define EVENT(h, e, d1, d2) \ +#define EVENT(h, e) \ do { \ if((h)->eventcb) { \ - (h)->eventcb(e, d1, d2); \ + (h)->eventcb((alpm_event_t *) (e)); \ } \ } while(0) #define QUESTION(h, q, d1, d2, d3, r) \ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 8884495..32d71ab 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,12 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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_REMOVED, pkg, optdep); + alpm_event_optdep_removed_t event = { + .type = ALPM_EVENT_OPTDEP_REMOVED, + .pkg = pkg, + .optdep = optdep + }; + EVENT(handle, &event); } } } @@ -203,6 +208,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_t *lp; alpm_trans_t *trans = handle->trans; alpm_db_t *db = handle->db_local; + alpm_event_t event;
if((trans->flags & ALPM_TRANS_FLAG_RECURSE) && !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) { @@ -214,7 +220,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) }
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1); @@ -261,7 +268,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) remove_notify_needed_optdepends(handle, trans->remove);
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_DONE; + EVENT(handle, &event); }
return 0; @@ -663,12 +671,18 @@ int _alpm_remove_single_package(alpm_handle_t *handle, { const char *pkgname = oldpkg->name; const char *pkgver = oldpkg->version; + alpm_event_update_t event = { + .type = ALPM_EVENT_UPDATE_START, + .operation = ALPM_OPERATION_REMOVE, + .oldpkg = oldpkg, + .newpkg = NULL + };
if(newpkg) { _alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n", pkgname, pkgver); } else { - EVENT(handle, ALPM_EVENT_REMOVE_START, oldpkg, NULL); + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n", pkgname, pkgver);
@@ -702,7 +716,8 @@ int _alpm_remove_single_package(alpm_handle_t *handle, }
if(!newpkg) { - EVENT(handle, ALPM_EVENT_REMOVE_DONE, oldpkg, NULL); + event.type = ALPM_EVENT_UPDATE_DONE; + EVENT(handle, &event); }
/* remove the package from the database */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 551f926..c79000c 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -369,6 +369,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) size_t from_sync = 0; int ret = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event;
if(data) { *data = NULL; @@ -398,7 +399,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
/* Build up list by repeatedly resolving each transaction package */ /* Resolve targets dependencies */ - EVENT(handle, ALPM_EVENT_RESOLVEDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n");
/* build remove list for resolvedeps */ @@ -474,12 +476,14 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_free(trans->add); trans->add = resolved;
- EVENT(handle, ALPM_EVENT_RESOLVEDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_DONE; + EVENT(handle, &event); }
if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) { /* check for inter-conflicts and whatnot */ - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n");
@@ -590,7 +594,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) goto cleanup; } } - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_DONE; + EVENT(handle, &event); alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free); alpm_list_free(deps); } @@ -679,6 +684,7 @@ static int apply_deltas(alpm_handle_t *handle) int deltas_found = 0, ret = 0; const char *cachedir = _alpm_filecache_setup(handle); alpm_trans_t *trans = handle->trans; + alpm_event_delta_patch_t event;
for(i = trans->add; i; i = i->next) { alpm_pkg_t *spkg = i->data; @@ -692,7 +698,8 @@ static int apply_deltas(alpm_handle_t *handle) if(!deltas_found) { /* only show this if we actually have deltas to apply, and it is before * the very first one */ - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_START; + EVENT(handle, &event); deltas_found = 1; }
@@ -726,11 +733,15 @@ static int apply_deltas(alpm_handle_t *handle)
_alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command);
- EVENT(handle, ALPM_EVENT_DELTA_PATCH_START, d->to, d->delta); + event.type = ALPM_EVENT_DELTA_PATCH_START; + event.pkg_filename = d->to; + event.patch_filename = d->delta; + EVENT(handle, &event);
int retval = system(command); if(retval == 0) { - EVENT(handle, ALPM_EVENT_DELTA_PATCH_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_DONE; + EVENT(handle, &event);
/* delete the delta file */ unlink(delta); @@ -748,7 +759,8 @@ static int apply_deltas(alpm_handle_t *handle)
if(retval != 0) { /* one delta failed for this package, cancel the remaining ones */ - EVENT(handle, ALPM_EVENT_DELTA_PATCH_FAILED, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_FAILED; + EVENT(handle, &event); handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED; ret = 1; break; @@ -756,7 +768,8 @@ static int apply_deltas(alpm_handle_t *handle) } } if(deltas_found) { - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_DONE; + EVENT(handle, &event); }
return ret; @@ -785,13 +798,15 @@ static int prompt_to_delete(alpm_handle_t *handle, const char *filepath, static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) { alpm_list_t *i, *errors = NULL; + alpm_event_t event;
if(!deltas) { return 0; }
/* Check integrity of deltas */ - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_START; + EVENT(handle, &event); for(i = deltas; i; i = i->next) { alpm_delta_t *d = i->data; char *filepath = _alpm_filecache_find(handle, d->delta); @@ -802,7 +817,8 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) FREE(filepath); } } - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_DONE; + EVENT(handle, &event);
if(errors) { for(i = errors; i; i = i->next) { @@ -908,6 +924,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) const char *cachedir; alpm_list_t *i, *files = NULL; int errors = 0; + alpm_event_t event;
cachedir = _alpm_filecache_setup(handle); handle->trans->state = STATE_DOWNLOADING; @@ -955,7 +972,8 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) } }
- EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL); + event.type = ALPM_EVENT_RETRIEVE_START; + EVENT(handle, &event); for(i = files; i; i = i->next) { if(download_single_file(handle, i->data, cachedir) == -1) { errors++; @@ -989,8 +1007,10 @@ static int check_keyring(alpm_handle_t *handle) { size_t current = 0, numtargs; alpm_list_t *i, *errors = NULL; + alpm_event_t event;
- EVENT(handle, ALPM_EVENT_KEYRING_START, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_START; + EVENT(handle, &event);
numtargs = alpm_list_count(handle->trans->add);
@@ -1033,10 +1053,12 @@ static int check_keyring(alpm_handle_t *handle)
PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", 100, numtargs, current); - EVENT(handle, ALPM_EVENT_KEYRING_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_DONE; + EVENT(handle, &event);
if(errors) { - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_START, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_START; + EVENT(handle, &event); int fail = 0; alpm_list_t *k; for(k = errors; k; k = k->next) { @@ -1045,7 +1067,8 @@ static int check_keyring(alpm_handle_t *handle) fail = 1; } } - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_DONE; + EVENT(handle, &event); if(fail) { _alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n")); return -1; @@ -1070,9 +1093,11 @@ static int check_validity(alpm_handle_t *handle, size_t current = 0; uint64_t current_bytes = 0; alpm_list_t *i, *errors = NULL; + alpm_event_t event;
/* Check integrity of packages */ - EVENT(handle, ALPM_EVENT_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_START; + EVENT(handle, &event);
for(i = handle->trans->add; i; i = i->next, current++) { struct validity v = { i->data, NULL, NULL, 0, 0, 0 }; @@ -1104,7 +1129,8 @@ static int check_validity(alpm_handle_t *handle,
PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_DONE; + EVENT(handle, &event);
if(errors) { for(i = errors; i; i = i->next) { @@ -1143,9 +1169,11 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, size_t current = 0, current_bytes = 0; int errors = 0; alpm_list_t *i; + alpm_event_t event;
/* load packages from disk now that they are known-valid */ - EVENT(handle, ALPM_EVENT_LOAD_START, NULL, NULL); + event.type = ALPM_EVENT_LOAD_START; + EVENT(handle, &event);
for(i = handle->trans->add; i; i = i->next, current++) { alpm_pkg_t *spkg = i->data; @@ -1186,7 +1214,8 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_LOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_LOAD_DONE; + EVENT(handle, &event);
if(errors) { if(!handle->pm_errno) { @@ -1204,6 +1233,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) size_t total = 0; uint64_t total_bytes = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event;
if(download_files(handle, &deltas)) { alpm_list_free(deltas); @@ -1262,7 +1292,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
/* fileconflict check */ if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_FILECONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n"); alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle, @@ -1277,12 +1308,14 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1); }
- EVENT(handle, ALPM_EVENT_FILECONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_DONE; + EVENT(handle, &event); }
/* check available disk space */ if(handle->checkspace && !(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_DISKSPACE_START, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n"); if(_alpm_check_diskspace(handle) == -1) { @@ -1290,7 +1323,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) return -1; }
- EVENT(handle, ALPM_EVENT_DISKSPACE_DONE, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_DONE; + EVENT(handle, &event); }
/* remove conflicting and to-be-replaced packages */ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index f9fdb01..4a9ea75 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -571,10 +571,14 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]) } else { while(!feof(pipe_file)) { char line[PATH_MAX]; + alpm_event_scriptlet_info_t event = { + .type = ALPM_EVENT_SCRIPTLET_INFO, + .line = line + }; if(fgets(line, PATH_MAX, pipe_file) == NULL) break; alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line); - EVENT(handle, ALPM_EVENT_SCRIPTLET_INFO, line, NULL); + EVENT(handle, &event); } fclose(pipe_file); } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index e80a071..040c2bd 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -149,12 +149,12 @@ static void fill_progress(const int bar_percent, const int disp_percent, }
/* callback to handle messages/notifications from libalpm transactions */ -void cb_event(alpm_event_t event, void *data1, void *data2) +void cb_event(alpm_event_t *event) { if(config->print) { return; } - switch(event) { + switch(event->type) { case ALPM_EVENT_CHECKDEPS_START: printf(_("checking dependencies...\n")); break; @@ -169,38 +169,43 @@ void cb_event(alpm_event_t event, void *data1, void *data2) case ALPM_EVENT_INTERCONFLICTS_START: printf(_("looking for conflicting packages...\n")); break; - case ALPM_EVENT_ADD_START: - if(config->noprogressbar) { - printf(_("installing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_ADD_DONE: - display_optdepends(data1); - break; - case ALPM_EVENT_REMOVE_START: + case ALPM_EVENT_UPDATE_START: if(config->noprogressbar) { - printf(_("removing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_START: - if(config->noprogressbar) { - printf(_("upgrading %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_DOWNGRADE_START: - if(config->noprogressbar) { - printf(_("downgrading %s...\n"), alpm_pkg_get_name(data1)); + alpm_event_update_t *e = (alpm_event_update_t *) event; + switch(e->operation) { + case ALPM_OPERATION_INSTALL: + printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_UPGRADE: + printf(_("upgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_REINSTALL: + printf(_("reinstalling %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_DOWNGRADE: + printf(_("downgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_REMOVE: + printf(_("removing %s...\n"), alpm_pkg_get_name(e->oldpkg)); + break; + } } break; - case ALPM_EVENT_DOWNGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_REINSTALL_START: - if(config->noprogressbar) { - printf(_("reinstalling %s...\n"), alpm_pkg_get_name(data1)); + case ALPM_EVENT_UPDATE_DONE: + { + alpm_event_update_t *e = (alpm_event_update_t *) event; + switch(e->operation) { + case ALPM_OPERATION_INSTALL: + display_optdepends(e->newpkg); + break; + case ALPM_OPERATION_UPGRADE: + case ALPM_OPERATION_DOWNGRADE: + display_new_optdepends(e->oldpkg, e->newpkg); + break; + case ALPM_OPERATION_REINSTALL: + case ALPM_OPERATION_REMOVE: + break; + } } break; case ALPM_EVENT_INTEGRITY_START: @@ -228,7 +233,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("applying deltas...\n")); break; case ALPM_EVENT_DELTA_PATCH_START: - printf(_("generating %s with %s... "), (char *)data1, (char *)data2); + { + alpm_event_delta_patch_t *e = (alpm_event_delta_patch_t *) event; + printf(_("generating %s with %s... "), e->pkg_filename, e->patch_filename); + } break; case ALPM_EVENT_DELTA_PATCH_DONE: printf(_("success!\n")); @@ -237,7 +245,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("failed.\n")); break; case ALPM_EVENT_SCRIPTLET_INFO: - fputs((const char *)data1, stdout); + fputs(((alpm_event_scriptlet_info_t *) event)->line, stdout); break; case ALPM_EVENT_RETRIEVE_START: colon_printf(_("Retrieving packages ...\n")); @@ -248,18 +256,21 @@ void cb_event(alpm_event_t event, void *data1, void *data2) } break; case ALPM_EVENT_OPTDEP_REMOVED: - colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), - alpm_dep_compute_string(data2)); + { + alpm_event_optdep_removed_t *e = (alpm_event_optdep_removed_t *) event; + colon_printf(_("%s optionally requires %s\n"), + alpm_pkg_get_name(e->pkg), + alpm_dep_compute_string(e->optdep)); + } break; case ALPM_EVENT_DATABASE_MISSING: if(!config->op_s_sync) { pm_printf(ALPM_LOG_WARNING, - "database file for '%s' does not exist\n", (char *)data1); + "database file for '%s' does not exist\n", + ((alpm_event_database_missing_t *) event)->dbname); } break; /* all the simple done events, with fallthrough for each */ - case ALPM_EVENT_REINSTALL_DONE: - case ALPM_EVENT_REMOVE_DONE: case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: case ALPM_EVENT_RESOLVEDEPS_DONE: diff --git a/src/pacman/callback.h b/src/pacman/callback.h index a291fc7..b19b952 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -25,7 +25,7 @@ #include <alpm.h>
/* callback to handle messages/notifications from libalpm */ -void cb_event(alpm_event_t event, void *data1, void *data2); +void cb_event(alpm_event_t *event);
/* callback to handle questions from libalpm (yes/no) */ void cb_question(alpm_question_t event, void *data1, void *data2,
On 12/15/13 13:10, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered.
With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I have given couple of suggestions below for naming that I think makes things clearer. Also a query regarding the delta event struct.
Otherwise, this looks good.
--- lib/libalpm/add.c | 31 ++++++----- lib/libalpm/alpm.h | 150 +++++++++++++++++++++++++++++--------------------- lib/libalpm/be_sync.c | 6 +- lib/libalpm/handle.h | 4 +- lib/libalpm/remove.c | 25 +++++++-- lib/libalpm/sync.c | 82 +++++++++++++++++++-------- lib/libalpm/util.c | 6 +- src/pacman/callback.c | 87 ++++++++++++++++------------- src/pacman/callback.h | 2 +- 9 files changed, 244 insertions(+), 149 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index c7e5b5d..3067df5 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -460,7 +460,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; alpm_progress_t progress = ALPM_PROGRESS_ADD_START; - alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; + alpm_event_update_t event; const char *log_msg = "adding"; const char *pkgfile;
@@ -473,18 +473,15 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, if(cmp < 0) { log_msg = "downgrading"; progress = ALPM_PROGRESS_DOWNGRADE_START; - start = ALPM_EVENT_DOWNGRADE_START; - done = ALPM_EVENT_DOWNGRADE_DONE; + event.operation = ALPM_OPERATION_DOWNGRADE; } else if(cmp == 0) { log_msg = "reinstalling"; progress = ALPM_PROGRESS_REINSTALL_START; - start = ALPM_EVENT_REINSTALL_START; - done = ALPM_EVENT_REINSTALL_DONE; + event.operation = ALPM_OPERATION_REINSTALL; } else { log_msg = "upgrading"; progress = ALPM_PROGRESS_UPGRADE_START; - start = ALPM_EVENT_UPGRADE_START; - done = ALPM_EVENT_UPGRADE_DONE; + event.operation = ALPM_OPERATION_UPGRADE; } is_upgrade = 1;
@@ -496,9 +493,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
/* copy over the install reason */ newpkg->reason = alpm_pkg_get_reason(local); + } else { + event.operation = ALPM_OPERATION_INSTALL; }
- EVENT(handle, start, newpkg, local); + event.type = ALPM_EVENT_UPDATE_START; + event.oldpkg = oldpkg; + event.newpkg = newpkg; + EVENT(handle, &event);
pkgfile = newpkg->origin_data.file;
@@ -649,20 +651,20 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current);
- switch(done) { - case ALPM_EVENT_ADD_DONE: + switch(event.operation) { + case ALPM_OPERATION_INSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "installed %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_DOWNGRADE_DONE: + case ALPM_OPERATION_DOWNGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "downgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; - case ALPM_EVENT_REINSTALL_DONE: + case ALPM_OPERATION_REINSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "reinstalled %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_UPGRADE_DONE: + case ALPM_OPERATION_UPGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "upgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; @@ -682,7 +684,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, free(scriptlet); }
- EVENT(handle, done, newpkg, oldpkg); + event.type = ALPM_EVENT_UPDATE_DONE; + EVENT(handle, &event);
cleanup: _alpm_pkg_free(oldpkg); diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index c6d9064..eba9375 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -275,10 +275,9 @@ int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
/** - * Events. - * NULL parameters are passed to in all events unless specified otherwise. + * Type of events. */ -typedef enum _alpm_event_t { +typedef enum _alpm_event_type_t { /** Dependencies will be computed for a package. */ ALPM_EVENT_CHECKDEPS_START = 1, /** Dependencies were computed for a package. */ @@ -295,49 +294,12 @@ typedef enum _alpm_event_t { ALPM_EVENT_INTERCONFLICTS_START, /** Inter-conflicts were checked for target package. */ ALPM_EVENT_INTERCONFLICTS_DONE, - /** Package will be installed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_ADD_START, - /** Package was installed. - * A pointer to the new package is passed to the callback. - */ - ALPM_EVENT_ADD_DONE, - /** Package will be removed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_REMOVE_START, - /** Package was removed. - * A pointer to the removed package is passed to the callback. - */ - ALPM_EVENT_REMOVE_DONE, - /** Package will be upgraded. - * A pointer to the upgraded package is passed to the callback. - */ - ALPM_EVENT_UPGRADE_START, - /** Package was upgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_UPGRADE_DONE, - /** Package will be downgraded. - * A pointer to the downgraded package is passed to the callback. - */ - ALPM_EVENT_DOWNGRADE_START, - /** Package was downgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_DOWNGRADE_DONE, - /** Package will be reinstalled. - * A pointer to the reinstalled package is passed to the callback. - */ - ALPM_EVENT_REINSTALL_START, - /** Package was reinstalled. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_REINSTALL_DONE, + /** Package will be installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_update_t for arguments. */ + ALPM_EVENT_UPDATE_START,
UPDATE does not sound right to me here. How about ALPM_EVENT_PACKAGE_OPERATION_START?
Yes, that sounds better.
+ /** Package was installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_update_t for arguments. */ + ALPM_EVENT_UPDATE_DONE, /** Target package's integrity will be checked. */ ALPM_EVENT_INTEGRITY_START, /** Target package's integrity was checked. */ @@ -354,31 +316,27 @@ typedef enum _alpm_event_t { ALPM_EVENT_DELTA_PATCHES_START, /** Deltas were applied to packages. */ ALPM_EVENT_DELTA_PATCHES_DONE, - /** Delta patch will be applied to target package. - * The filename of the package and the filename of the patch is passed to the - * callback. - */ + /** Delta patch will be applied to target package; See + * alpm_event_delta_patch_t for arguments.. */ ALPM_EVENT_DELTA_PATCH_START, /** Delta patch was applied to target package. */ ALPM_EVENT_DELTA_PATCH_DONE, /** Delta patch failed to apply to target package. */ ALPM_EVENT_DELTA_PATCH_FAILED, - /** Scriptlet has printed information. - * A line of text is passed to the callback. - */ + /** Scriptlet has printed information; See alpm_event_scriptlet_info_t for + * arguments. */ ALPM_EVENT_SCRIPTLET_INFO, - /** Files will be downloaded from a repository. - * The repository's tree name is passed to the callback. - */ + /** Files will be downloaded from a repository. */ ALPM_EVENT_RETRIEVE_START, - /** Disk space usage will be computed for a package */ + /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, - /** Disk space usage was computed for a package */ + /** Disk space usage was computed for a package. */ ALPM_EVENT_DISKSPACE_DONE, - /** An optdepend for another package is being removed - * The requiring package and its dependency are passed to the callback */ + /** An optdepend for another package is being removed; See + * alpm_event_optdep_removed_t for arguments. */ ALPM_EVENT_OPTDEP_REMOVED, - /** A configured repository database is missing */ + /** A configured repository database is missing; See + * alpm_event_database_missing_t for arguments. */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ ALPM_EVENT_KEYRING_START, @@ -388,10 +346,76 @@ typedef enum _alpm_event_t { ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE +} alpm_event_type_t; + +/** Events. + * This is a generic struct this is passed to the callback, that allows the + * frontend to know which type of event was triggered. It is then possible to + * typecast the pointer to the right structure, in order to access + * event-specific data. */ +typedef struct _alpm_event_t { + /** Type of event. */ + alpm_event_type_t type; } alpm_event_t;
-/** Event callback */ -typedef void (*alpm_cb_event)(alpm_event_t, void *, void *); +typedef enum _alpm_pkg_operation_t {
_alpm_package_operation_t
+ /** Package (to be) installed. (No oldpkg) */ + ALPM_OPERATION_INSTALL = 1,
ALPM_PACKAGE_INSTALL
+ /** Package (to be) upgraded */ + ALPM_OPERATION_UPGRADE, + /** Package (to be) re-installed. */ + ALPM_OPERATION_REINSTALL, + /** Package (to be) downgraded. */ + ALPM_OPERATION_DOWNGRADE, + /** Package (to be) removed. (No newpkg) */ + ALPM_OPERATION_REMOVE +} alpm_operation_t;
alpm_package_operation_t
+typedef struct _alpm_event_update_t {
_alpm_event_package_operation_t
+ /** Type of event. */ + alpm_event_type_t type; + /** Type of operation. */ + alpm_operation_t operation; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New package. */ + alpm_pkg_t *newpkg; +} alpm_event_update_t; + +typedef struct _alpm_event_optdep_removed_t { + /** Type of event. */ + alpm_event_type_t type; + /** Package with the optdep. */ + alpm_pkg_t *pkg; + /** Optdep being removed. */ + alpm_depend_t *optdep; +} alpm_event_optdep_removed_t; + +typedef struct _alpm_event_delta_patch_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the file. */ + const char *pkg_filename; + /** Name of the patch. */ + const char *patch_filename;
Any reason to not just pass the alpm_delta_t* here?
I don't think so, I just kept the same arguments as before. Looking at the log it doesn't seem there is a reason to not send the alpm_delta_t* currently, so I'll do that instead yes.
+} alpm_event_delta_patch_t; + +typedef struct _alpm_event_scriptlet_info_t { + /** Type of event. */ + alpm_event_type_t type; + /** Line of scriptlet output. */ + const char *line; +} alpm_event_scriptlet_info_t; + +typedef struct _alpm_event_database_missing_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the database. */ + const char *dbname; +} alpm_event_database_missing_t; + +/** Event callback. */ +typedef void (*alpm_cb_event)(alpm_event_t *);
/** * Questions. diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 123d953..3f3d54f 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -89,9 +89,13 @@ static int sync_db_validate(alpm_db_t *db)
/* we can skip any validation if the database doesn't exist */ if(_alpm_access(db->handle, NULL, dbpath, R_OK) != 0 && errno == ENOENT) { + alpm_event_database_missing_t event = { + .type = ALPM_EVENT_DATABASE_MISSING, + .dbname = db->treename + }; db->status &= ~DB_STATUS_EXISTS; db->status |= DB_STATUS_MISSING; - EVENT(db->handle, ALPM_EVENT_DATABASE_MISSING, db->treename, NULL); + EVENT(db->handle, &event); goto valid; } db->status |= DB_STATUS_EXISTS; diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 4126e1a..4275d13 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -31,10 +31,10 @@ #include <curl/curl.h> #endif
-#define EVENT(h, e, d1, d2) \ +#define EVENT(h, e) \ do { \ if((h)->eventcb) { \ - (h)->eventcb(e, d1, d2); \ + (h)->eventcb((alpm_event_t *) (e)); \ } \ } while(0) #define QUESTION(h, q, d1, d2, d3, r) \ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 8884495..32d71ab 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,12 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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_REMOVED, pkg, optdep); + alpm_event_optdep_removed_t event = { + .type = ALPM_EVENT_OPTDEP_REMOVED, + .pkg = pkg, + .optdep = optdep + }; + EVENT(handle, &event); } } } @@ -203,6 +208,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_t *lp; alpm_trans_t *trans = handle->trans; alpm_db_t *db = handle->db_local; + alpm_event_t event;
if((trans->flags & ALPM_TRANS_FLAG_RECURSE) && !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) { @@ -214,7 +220,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) }
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1); @@ -261,7 +268,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) remove_notify_needed_optdepends(handle, trans->remove);
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_DONE; + EVENT(handle, &event); }
return 0; @@ -663,12 +671,18 @@ int _alpm_remove_single_package(alpm_handle_t *handle, { const char *pkgname = oldpkg->name; const char *pkgver = oldpkg->version; + alpm_event_update_t event = { + .type = ALPM_EVENT_UPDATE_START, + .operation = ALPM_OPERATION_REMOVE, + .oldpkg = oldpkg, + .newpkg = NULL + };
if(newpkg) { _alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n", pkgname, pkgver); } else { - EVENT(handle, ALPM_EVENT_REMOVE_START, oldpkg, NULL); + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n", pkgname, pkgver);
@@ -702,7 +716,8 @@ int _alpm_remove_single_package(alpm_handle_t *handle, }
if(!newpkg) { - EVENT(handle, ALPM_EVENT_REMOVE_DONE, oldpkg, NULL); + event.type = ALPM_EVENT_UPDATE_DONE; + EVENT(handle, &event); }
/* remove the package from the database */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 551f926..c79000c 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -369,6 +369,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) size_t from_sync = 0; int ret = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event;
if(data) { *data = NULL; @@ -398,7 +399,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
/* Build up list by repeatedly resolving each transaction package */ /* Resolve targets dependencies */ - EVENT(handle, ALPM_EVENT_RESOLVEDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n");
/* build remove list for resolvedeps */ @@ -474,12 +476,14 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_free(trans->add); trans->add = resolved;
- EVENT(handle, ALPM_EVENT_RESOLVEDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_DONE; + EVENT(handle, &event); }
if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) { /* check for inter-conflicts and whatnot */ - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n");
@@ -590,7 +594,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) goto cleanup; } } - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_DONE; + EVENT(handle, &event); alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free); alpm_list_free(deps); } @@ -679,6 +684,7 @@ static int apply_deltas(alpm_handle_t *handle) int deltas_found = 0, ret = 0; const char *cachedir = _alpm_filecache_setup(handle); alpm_trans_t *trans = handle->trans; + alpm_event_delta_patch_t event;
for(i = trans->add; i; i = i->next) { alpm_pkg_t *spkg = i->data; @@ -692,7 +698,8 @@ static int apply_deltas(alpm_handle_t *handle) if(!deltas_found) { /* only show this if we actually have deltas to apply, and it is before * the very first one */ - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_START; + EVENT(handle, &event); deltas_found = 1; }
@@ -726,11 +733,15 @@ static int apply_deltas(alpm_handle_t *handle)
_alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command);
- EVENT(handle, ALPM_EVENT_DELTA_PATCH_START, d->to, d->delta); + event.type = ALPM_EVENT_DELTA_PATCH_START; + event.pkg_filename = d->to; + event.patch_filename = d->delta; + EVENT(handle, &event);
int retval = system(command); if(retval == 0) { - EVENT(handle, ALPM_EVENT_DELTA_PATCH_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_DONE; + EVENT(handle, &event);
/* delete the delta file */ unlink(delta); @@ -748,7 +759,8 @@ static int apply_deltas(alpm_handle_t *handle)
if(retval != 0) { /* one delta failed for this package, cancel the remaining ones */ - EVENT(handle, ALPM_EVENT_DELTA_PATCH_FAILED, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_FAILED; + EVENT(handle, &event); handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED; ret = 1; break; @@ -756,7 +768,8 @@ static int apply_deltas(alpm_handle_t *handle) } } if(deltas_found) { - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_DONE; + EVENT(handle, &event); }
return ret; @@ -785,13 +798,15 @@ static int prompt_to_delete(alpm_handle_t *handle, const char *filepath, static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) { alpm_list_t *i, *errors = NULL; + alpm_event_t event;
if(!deltas) { return 0; }
/* Check integrity of deltas */ - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_START; + EVENT(handle, &event); for(i = deltas; i; i = i->next) { alpm_delta_t *d = i->data; char *filepath = _alpm_filecache_find(handle, d->delta); @@ -802,7 +817,8 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) FREE(filepath); } } - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_DONE; + EVENT(handle, &event);
if(errors) { for(i = errors; i; i = i->next) { @@ -908,6 +924,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) const char *cachedir; alpm_list_t *i, *files = NULL; int errors = 0; + alpm_event_t event;
cachedir = _alpm_filecache_setup(handle); handle->trans->state = STATE_DOWNLOADING; @@ -955,7 +972,8 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) } }
- EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL); + event.type = ALPM_EVENT_RETRIEVE_START; + EVENT(handle, &event); for(i = files; i; i = i->next) { if(download_single_file(handle, i->data, cachedir) == -1) { errors++; @@ -989,8 +1007,10 @@ static int check_keyring(alpm_handle_t *handle) { size_t current = 0, numtargs; alpm_list_t *i, *errors = NULL; + alpm_event_t event;
- EVENT(handle, ALPM_EVENT_KEYRING_START, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_START; + EVENT(handle, &event);
numtargs = alpm_list_count(handle->trans->add);
@@ -1033,10 +1053,12 @@ static int check_keyring(alpm_handle_t *handle)
PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", 100, numtargs, current); - EVENT(handle, ALPM_EVENT_KEYRING_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_DONE; + EVENT(handle, &event);
if(errors) { - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_START, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_START; + EVENT(handle, &event); int fail = 0; alpm_list_t *k; for(k = errors; k; k = k->next) { @@ -1045,7 +1067,8 @@ static int check_keyring(alpm_handle_t *handle) fail = 1; } } - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_DONE; + EVENT(handle, &event); if(fail) { _alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n")); return -1; @@ -1070,9 +1093,11 @@ static int check_validity(alpm_handle_t *handle, size_t current = 0; uint64_t current_bytes = 0; alpm_list_t *i, *errors = NULL; + alpm_event_t event;
/* Check integrity of packages */ - EVENT(handle, ALPM_EVENT_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_START; + EVENT(handle, &event);
for(i = handle->trans->add; i; i = i->next, current++) { struct validity v = { i->data, NULL, NULL, 0, 0, 0 }; @@ -1104,7 +1129,8 @@ static int check_validity(alpm_handle_t *handle,
PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_DONE; + EVENT(handle, &event);
if(errors) { for(i = errors; i; i = i->next) { @@ -1143,9 +1169,11 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, size_t current = 0, current_bytes = 0; int errors = 0; alpm_list_t *i; + alpm_event_t event;
/* load packages from disk now that they are known-valid */ - EVENT(handle, ALPM_EVENT_LOAD_START, NULL, NULL); + event.type = ALPM_EVENT_LOAD_START; + EVENT(handle, &event);
for(i = handle->trans->add; i; i = i->next, current++) { alpm_pkg_t *spkg = i->data; @@ -1186,7 +1214,8 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_LOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_LOAD_DONE; + EVENT(handle, &event);
if(errors) { if(!handle->pm_errno) { @@ -1204,6 +1233,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) size_t total = 0; uint64_t total_bytes = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event;
if(download_files(handle, &deltas)) { alpm_list_free(deltas); @@ -1262,7 +1292,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
/* fileconflict check */ if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_FILECONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n"); alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle, @@ -1277,12 +1308,14 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1); }
- EVENT(handle, ALPM_EVENT_FILECONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_DONE; + EVENT(handle, &event); }
/* check available disk space */ if(handle->checkspace && !(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_DISKSPACE_START, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_START; + EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n"); if(_alpm_check_diskspace(handle) == -1) { @@ -1290,7 +1323,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) return -1; }
- EVENT(handle, ALPM_EVENT_DISKSPACE_DONE, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_DONE; + EVENT(handle, &event); }
/* remove conflicting and to-be-replaced packages */ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index f9fdb01..4a9ea75 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -571,10 +571,14 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]) } else { while(!feof(pipe_file)) { char line[PATH_MAX]; + alpm_event_scriptlet_info_t event = { + .type = ALPM_EVENT_SCRIPTLET_INFO, + .line = line + }; if(fgets(line, PATH_MAX, pipe_file) == NULL) break; alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line); - EVENT(handle, ALPM_EVENT_SCRIPTLET_INFO, line, NULL); + EVENT(handle, &event); } fclose(pipe_file); } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index e80a071..040c2bd 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -149,12 +149,12 @@ static void fill_progress(const int bar_percent, const int disp_percent, }
/* callback to handle messages/notifications from libalpm transactions */ -void cb_event(alpm_event_t event, void *data1, void *data2) +void cb_event(alpm_event_t *event) { if(config->print) { return; } - switch(event) { + switch(event->type) { case ALPM_EVENT_CHECKDEPS_START: printf(_("checking dependencies...\n")); break; @@ -169,38 +169,43 @@ void cb_event(alpm_event_t event, void *data1, void *data2) case ALPM_EVENT_INTERCONFLICTS_START: printf(_("looking for conflicting packages...\n")); break; - case ALPM_EVENT_ADD_START: - if(config->noprogressbar) { - printf(_("installing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_ADD_DONE: - display_optdepends(data1); - break; - case ALPM_EVENT_REMOVE_START: + case ALPM_EVENT_UPDATE_START: if(config->noprogressbar) { - printf(_("removing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_START: - if(config->noprogressbar) { - printf(_("upgrading %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_DOWNGRADE_START: - if(config->noprogressbar) { - printf(_("downgrading %s...\n"), alpm_pkg_get_name(data1)); + alpm_event_update_t *e = (alpm_event_update_t *) event; + switch(e->operation) { + case ALPM_OPERATION_INSTALL: + printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_UPGRADE: + printf(_("upgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_REINSTALL: + printf(_("reinstalling %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_DOWNGRADE: + printf(_("downgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_OPERATION_REMOVE: + printf(_("removing %s...\n"), alpm_pkg_get_name(e->oldpkg)); + break; + } } break; - case ALPM_EVENT_DOWNGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_REINSTALL_START: - if(config->noprogressbar) { - printf(_("reinstalling %s...\n"), alpm_pkg_get_name(data1)); + case ALPM_EVENT_UPDATE_DONE: + { + alpm_event_update_t *e = (alpm_event_update_t *) event; + switch(e->operation) { + case ALPM_OPERATION_INSTALL: + display_optdepends(e->newpkg); + break; + case ALPM_OPERATION_UPGRADE: + case ALPM_OPERATION_DOWNGRADE: + display_new_optdepends(e->oldpkg, e->newpkg); + break; + case ALPM_OPERATION_REINSTALL: + case ALPM_OPERATION_REMOVE: + break; + } } break; case ALPM_EVENT_INTEGRITY_START: @@ -228,7 +233,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("applying deltas...\n")); break; case ALPM_EVENT_DELTA_PATCH_START: - printf(_("generating %s with %s... "), (char *)data1, (char *)data2); + { + alpm_event_delta_patch_t *e = (alpm_event_delta_patch_t *) event; + printf(_("generating %s with %s... "), e->pkg_filename, e->patch_filename); + } break; case ALPM_EVENT_DELTA_PATCH_DONE: printf(_("success!\n")); @@ -237,7 +245,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("failed.\n")); break; case ALPM_EVENT_SCRIPTLET_INFO: - fputs((const char *)data1, stdout); + fputs(((alpm_event_scriptlet_info_t *) event)->line, stdout); break; case ALPM_EVENT_RETRIEVE_START: colon_printf(_("Retrieving packages ...\n")); @@ -248,18 +256,21 @@ void cb_event(alpm_event_t event, void *data1, void *data2) } break; case ALPM_EVENT_OPTDEP_REMOVED: - colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), - alpm_dep_compute_string(data2)); + { + alpm_event_optdep_removed_t *e = (alpm_event_optdep_removed_t *) event; + colon_printf(_("%s optionally requires %s\n"), + alpm_pkg_get_name(e->pkg), + alpm_dep_compute_string(e->optdep)); + } break; case ALPM_EVENT_DATABASE_MISSING: if(!config->op_s_sync) { pm_printf(ALPM_LOG_WARNING, - "database file for '%s' does not exist\n", (char *)data1); + "database file for '%s' does not exist\n", + ((alpm_event_database_missing_t *) event)->dbname); } break; /* all the simple done events, with fallthrough for each */ - case ALPM_EVENT_REINSTALL_DONE: - case ALPM_EVENT_REMOVE_DONE: case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: case ALPM_EVENT_RESOLVEDEPS_DONE: diff --git a/src/pacman/callback.h b/src/pacman/callback.h index a291fc7..b19b952 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -25,7 +25,7 @@ #include <alpm.h>
/* callback to handle messages/notifications from libalpm */ -void cb_event(alpm_event_t event, void *data1, void *data2); +void cb_event(alpm_event_t *event);
/* callback to handle questions from libalpm (yes/no) */ void cb_question(alpm_question_t event, void *data1, void *data2,
On 12/15/13 13:10, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered.
With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I have given couple of suggestions below for naming that I think makes things clearer. Also a query regarding the delta event struct.
Otherwise, this looks good.
Alright, I've rebased & updated the patches regarding all the comments made. A couple of things before I resend them though: - What's your opinion regarding what I mentioned before: I don't think addressing FS#36504 was right. This was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. I think this might have been a mistake: I guess it all depends on when you consider the operation to be completed, once pacman's extraction reached 100%, or after the scriptlet have run. I feel the later is right, since they are part of the process of installing/upgrading/etc a package; Of course, you may disagree. Either way, the current situation is wrong, because right now ALPM does: 1. add log message about the operation being done 2. run scriptlet 3. signal frontend (via event) that operation is done IOW if a frontend was to actually use the event to present its output to the user, it wouldn't match the order in the log, which is wrong. This was done because pacman ignores that event, only showing the progress of the extraction, and thus people feel that it goes 1. install done; then 2. scriptlet. In fact, pacman doesn't really ignore the event, and uses it to show (new) optdep. Should this be done before or after the scriptlet? One could also ask, when using --noprogressbar pacman doesn't say anything at the end of the operation (save for optdep), imagine it would: should it be before or after the scriptlet? As I said, I think the logging should be moved after the scriptlet have run, as this is when the operation is really done. If you were to disagree though, then the event should be moved before the scriptlet run, to keep consistency between the frontend and the log (which is broken ATM), but this just feels wrong to me, since then a frontend would consider a package upgrade/etc done, when in fact the scriptlet have yet to run (and produce new output relating to the operation supposedly done). - Any comments on the last 3 patches (adding new events)? -j
On 10/01/14 23:14, Olivier Brunel wrote:
On 12/15/13 13:10, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered.
With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I have given couple of suggestions below for naming that I think makes things clearer. Also a query regarding the delta event struct.
Otherwise, this looks good.
Alright, I've rebased & updated the patches regarding all the comments made. A couple of things before I resend them though:
- What's your opinion regarding what I mentioned before: I don't think addressing FS#36504 was right. This was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. I think this might have been a mistake: I guess it all depends on when you consider the operation to be completed, once pacman's extraction reached 100%, or after the scriptlet have run. I feel the later is right, since they are part of the process of installing/upgrading/etc a package; Of course, you may disagree.
Either way, the current situation is wrong, because right now ALPM does: 1. add log message about the operation being done 2. run scriptlet 3. signal frontend (via event) that operation is done
IOW if a frontend was to actually use the event to present its output to the user, it wouldn't match the order in the log, which is wrong. This was done because pacman ignores that event, only showing the progress of the extraction, and thus people feel that it goes 1. install done; then 2. scriptlet.
In fact, pacman doesn't really ignore the event, and uses it to show (new) optdep. Should this be done before or after the scriptlet? One could also ask, when using --noprogressbar pacman doesn't say anything at the end of the operation (save for optdep), imagine it would: should it be before or after the scriptlet?
As I said, I think the logging should be moved after the scriptlet have run, as this is when the operation is really done. If you were to disagree though, then the event should be moved before the scriptlet run, to keep consistency between the frontend and the log (which is broken ATM), but this just feels wrong to me, since then a frontend would consider a package upgrade/etc done, when in fact the scriptlet have yet to run (and produce new output relating to the operation supposedly done).
I'd like Andrew to comment here as I think that was his patch. I think arguments can be make both ways here. Maybe signal the frontend it is done installingg at the same time as the log and add signals that install scriptlets are running? I think this is independent of your patchset, or am I missing something?
- Any comments on the last 3 patches (adding new events)?
On patchwork [1], I have flagged "Add events ALPM_EVENT_RETRIEVE_{DONE, FAILED}" as accepted. I think "Add events _PKGDOWNLOAD_{START, DONE, FAILED}" looks OK too at first glance. Can you put "Add events on pacnew/pacsave/pacorig file creation" at the end of your patch set? It is probably OK, but I have not looked too hard yet and it will be easier to merge that last if it is at the end. Cheers, Allan [1] https://patchwork.archlinux.org/project/pacman/list/?state=*
On 01/10/14 14:25, Allan McRae wrote:
On 10/01/14 23:14, Olivier Brunel wrote:
On 12/15/13 13:10, Allan McRae wrote:
On 03/12/13 06:45, Olivier Brunel wrote:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered.
With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
I have given couple of suggestions below for naming that I think makes things clearer. Also a query regarding the delta event struct.
Otherwise, this looks good.
Alright, I've rebased & updated the patches regarding all the comments made. A couple of things before I resend them though:
- What's your opinion regarding what I mentioned before: I don't think addressing FS#36504 was right. This was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. I think this might have been a mistake: I guess it all depends on when you consider the operation to be completed, once pacman's extraction reached 100%, or after the scriptlet have run. I feel the later is right, since they are part of the process of installing/upgrading/etc a package; Of course, you may disagree.
Either way, the current situation is wrong, because right now ALPM does: 1. add log message about the operation being done 2. run scriptlet 3. signal frontend (via event) that operation is done
IOW if a frontend was to actually use the event to present its output to the user, it wouldn't match the order in the log, which is wrong. This was done because pacman ignores that event, only showing the progress of the extraction, and thus people feel that it goes 1. install done; then 2. scriptlet.
In fact, pacman doesn't really ignore the event, and uses it to show (new) optdep. Should this be done before or after the scriptlet? One could also ask, when using --noprogressbar pacman doesn't say anything at the end of the operation (save for optdep), imagine it would: should it be before or after the scriptlet?
As I said, I think the logging should be moved after the scriptlet have run, as this is when the operation is really done. If you were to disagree though, then the event should be moved before the scriptlet run, to keep consistency between the frontend and the log (which is broken ATM), but this just feels wrong to me, since then a frontend would consider a package upgrade/etc done, when in fact the scriptlet have yet to run (and produce new output relating to the operation supposedly done).
I'd like Andrew to comment here as I think that was his patch. I think arguments can be make both ways here. Maybe signal the frontend it is done installingg at the same time as the log and add signals that install scriptlets are running? I think this is independent of your patchset, or am I missing something?
Yeah it is, I did keep things (in) the same (order) and the fix should be a separate patch indeed, I just didn't want this to be forgotten is all.
- Any comments on the last 3 patches (adding new events)?
On patchwork [1], I have flagged "Add events ALPM_EVENT_RETRIEVE_{DONE, FAILED}" as accepted. I think "Add events _PKGDOWNLOAD_{START, DONE, FAILED}" looks OK too at first glance. Can you put "Add events on pacnew/pacsave/pacorig file creation" at the end of your patch set? It is probably OK, but I have not looked too hard yet and it will be easier to merge that last if it is at the end.
Will do.
Cheers, Allan
[1] https://patchwork.archlinux.org/project/pacman/list/?state=*
On 01/10/14 at 03:16pm, Olivier Brunel wrote:
On 01/10/14 14:25, Allan McRae wrote:
On 10/01/14 23:14, Olivier Brunel wrote:
- What's your opinion regarding what I mentioned before: I don't think addressing FS#36504 was right. This was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. I think this might have been a mistake: I guess it all depends on when you consider the operation to be completed, once pacman's extraction reached 100%, or after the scriptlet have run. I feel the later is right, since they are part of the process of installing/upgrading/etc a package; Of course, you may disagree.
Either way, the current situation is wrong, because right now ALPM does: 1. add log message about the operation being done 2. run scriptlet 3. signal frontend (via event) that operation is done
IOW if a frontend was to actually use the event to present its output to the user, it wouldn't match the order in the log, which is wrong. This was done because pacman ignores that event, only showing the progress of the extraction, and thus people feel that it goes 1. install done; then 2. scriptlet.
In fact, pacman doesn't really ignore the event, and uses it to show (new) optdep. Should this be done before or after the scriptlet? One could also ask, when using --noprogressbar pacman doesn't say anything at the end of the operation (save for optdep), imagine it would: should it be before or after the scriptlet?
As I said, I think the logging should be moved after the scriptlet have run, as this is when the operation is really done. If you were to disagree though, then the event should be moved before the scriptlet run, to keep consistency between the frontend and the log (which is broken ATM), but this just feels wrong to me, since then a frontend would consider a package upgrade/etc done, when in fact the scriptlet have yet to run (and produce new output relating to the operation supposedly done).
I'd like Andrew to comment here as I think that was his patch. I think arguments can be make both ways here. Maybe signal the frontend it is done installingg at the same time as the log and add signals that install scriptlets are running? I think this is independent of your patchset, or am I missing something?
Yeah it is, I did keep things (in) the same (order) and the fix should be a separate patch indeed, I just didn't want this to be forgotten is all.
If I understand your proposal, you're suggesting that we *break* pacman's consistency with the log in order to make it easier for other front-ends to be consistent with it. That seems like a step in the wrong direction if you care about front-end/log consistency. The reason I moved the logging was really about log integrity. Resolving FS#36504 was just a happy coincidence. The log and front-end output serve two different purposes, and their similarity is not very important (they aren't even in the same language for non-English users). The log should reflect the current state of the system. As far as alpm is concerned, the package is installed as soon as it's added to the local db, so that is the correct time to log it. I would imagine that users and, by extension, front-ends are generally more likely to be interested in when the entire installation process, including scripts, is done. I would be fine with adding new events as Allan suggested as long as the end of the entire installation process can still be reliably detected by the front-end. Spawning a new process and running arbitrary code from the packager does seem like the sort of thing we should be notifying front-ends about anyway. apg
On 01/12/14 15:33, Andrew Gregory wrote:
On 01/10/14 at 03:16pm, Olivier Brunel wrote:
On 01/10/14 14:25, Allan McRae wrote:
On 10/01/14 23:14, Olivier Brunel wrote:
- What's your opinion regarding what I mentioned before: I don't think addressing FS#36504 was right. This was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. I think this might have been a mistake: I guess it all depends on when you consider the operation to be completed, once pacman's extraction reached 100%, or after the scriptlet have run. I feel the later is right, since they are part of the process of installing/upgrading/etc a package; Of course, you may disagree.
Either way, the current situation is wrong, because right now ALPM does: 1. add log message about the operation being done 2. run scriptlet 3. signal frontend (via event) that operation is done
IOW if a frontend was to actually use the event to present its output to the user, it wouldn't match the order in the log, which is wrong. This was done because pacman ignores that event, only showing the progress of the extraction, and thus people feel that it goes 1. install done; then 2. scriptlet.
In fact, pacman doesn't really ignore the event, and uses it to show (new) optdep. Should this be done before or after the scriptlet? One could also ask, when using --noprogressbar pacman doesn't say anything at the end of the operation (save for optdep), imagine it would: should it be before or after the scriptlet?
As I said, I think the logging should be moved after the scriptlet have run, as this is when the operation is really done. If you were to disagree though, then the event should be moved before the scriptlet run, to keep consistency between the frontend and the log (which is broken ATM), but this just feels wrong to me, since then a frontend would consider a package upgrade/etc done, when in fact the scriptlet have yet to run (and produce new output relating to the operation supposedly done).
I'd like Andrew to comment here as I think that was his patch. I think arguments can be make both ways here. Maybe signal the frontend it is done installingg at the same time as the log and add signals that install scriptlets are running? I think this is independent of your patchset, or am I missing something?
Yeah it is, I did keep things (in) the same (order) and the fix should be a separate patch indeed, I just didn't want this to be forgotten is all.
If I understand your proposal, you're suggesting that we *break* pacman's consistency with the log in order to make it easier for other front-ends to be consistent with it. That seems like a step in the wrong direction if you care about front-end/log consistency.
Ok, after looking into this more, it seems the issue might be one of log/frontend "consistency," or more specifically what the log message "package updated" means. As in, I was linking it to the entire package operation, and therefore it was (in my mind) linked to the corresponding event. The fact that the logging of the message & the event occurred at different moment was then thought of as a mistake. You seem, OTOH, to link it to mean the db update was done, nothing else -- it just so happens that pre-install scriptlet & file extraction, when performed, takes place prior to db update, while post-install scriptlet do not, but that's irrelevant. I get the point about how "the log should reflect the current state of the system" to want to place the log message at that moment, but I'm not sure about it. As in, I feel it would make more sense (from a user perspective?) if all log messages relating to a package were found before the "package installed" one, and not some before (e.g. pre-scriptlet, some warnings: pacnew, etc) and some after (post-scriptlet). Seems clearer/more consistent. Besides, it's not like all log messages allow to reflect the state of the system, after all the "synchronizing package lists" doesn't mean anything in that regard, really (you don't know which repos/dbs were upgraded, if any). And, again, as far as users go (not ALPM), a package is installed when the entire package operation is done, not just the db update. In a way it relates to the FS#36504, which was about moving the log messages about a package being installed/upgraded/etc before the scriptlet messages, and not after as they were. The reasoning given was that pacman does it the other way around, which is actually wrong (it appears that way when you view the 100% of the file extraction process to mean operation completed, which it isn't yet), if you consider the entire package operation. (In fact, pacman might add extra output after the operation is done, things about optdep. This happend after the operation is done, i.e. on the event, so after the scriptlet have run, not before.) It might look like there's no consistency between pacman & the log only because pacman doesn't show any output at the end of the package operation, so people assume the 100% of file extraction was it. It wasn't. But if you insist that the log message should reflect the db update operation, then I guess everything happens at the right moment. I myself still feel this would be more of a debug message (which already exist), and this regular log message really should refer to the (entire) package operation (and therefore be moved after post-scriptlet). -j
The reason I moved the logging was really about log integrity. Resolving FS#36504 was just a happy coincidence. The log and front-end output serve two different purposes, and their similarity is not very important (they aren't even in the same language for non-English users). The log should reflect the current state of the system. As far as alpm is concerned, the package is installed as soon as it's added to the local db, so that is the correct time to log it.
I would imagine that users and, by extension, front-ends are generally more likely to be interested in when the entire installation process, including scripts, is done. I would be fine with adding new events as Allan suggested as long as the end of the entire installation process can still be reliably detected by the front-end. Spawning a new process and running arbitrary code from the packager does seem like the sort of thing we should be notifying front-ends about anyway.
apg
When ALPM emits a log message, it still goes through _alpm_log() but instead of calling a specific log callback, it goes as an event. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 37 +++++++++++++++++++++---------------- lib/libalpm/handle.c | 13 ------------- lib/libalpm/handle.h | 1 - lib/libalpm/log.c | 14 +++++++++----- src/pacman/callback.c | 36 ++++++++++++++++++------------------ src/pacman/callback.h | 4 ---- src/pacman/conf.c | 1 - src/util/cleanupdelta.c | 14 ++++++++------ src/util/testdb.c | 14 ++++++++------ src/util/testpkg.c | 14 ++++++++------ 10 files changed, 72 insertions(+), 76 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index eba9375..bf11e41 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -261,16 +261,6 @@ typedef struct _alpm_siglist_t { * Logging facilities */ -/** Logging Levels */ -typedef enum _alpm_loglevel_t { - ALPM_LOG_ERROR = 1, - ALPM_LOG_WARNING = (1 << 1), - ALPM_LOG_DEBUG = (1 << 2), - ALPM_LOG_FUNCTION = (1 << 3) -} alpm_loglevel_t; - -typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list); - int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4))); @@ -345,7 +335,9 @@ typedef enum _alpm_event_type_t { /** Downloading missing keys into keyring. */ ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ - ALPM_EVENT_KEY_DOWNLOAD_DONE + ALPM_EVENT_KEY_DOWNLOAD_DONE, + /** A log message was emitted; See alpm_event_log_t for arguments. */ + ALPM_EVENT_LOG } alpm_event_type_t; /** Events. @@ -414,6 +406,24 @@ typedef struct _alpm_event_database_missing_t { const char *dbname; } alpm_event_database_missing_t; +/** Log levels. */ +typedef enum _alpm_loglevel_t { + ALPM_LOG_ERROR = 1, + ALPM_LOG_WARNING = (1 << 1), + ALPM_LOG_DEBUG = (1 << 2), + ALPM_LOG_FUNCTION = (1 << 3) +} alpm_loglevel_t; + +typedef struct _alpm_event_log_t { + /** Type of event. */ + alpm_event_type_t type; + /** Log level. */ + alpm_loglevel_t level; + /** Message. */ + const char *fmt; + va_list args; +} alpm_event_log_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); @@ -489,11 +499,6 @@ char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url); * @{ */ -/** Returns the callback used for logging. */ -alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle); -/** Sets the callback used for logging. */ -int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb); - /** Returns the callback used to report download progress. */ alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle); /** Sets the callback used to report download progress. */ diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 1d661a2..4c567ea 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -132,12 +132,6 @@ int _alpm_handle_unlock(alpm_handle_t *handle) } -alpm_cb_log SYMEXPORT alpm_option_get_logcb(alpm_handle_t *handle) -{ - CHECK_HANDLE(handle, return NULL); - return handle->logcb; -} - alpm_cb_download SYMEXPORT alpm_option_get_dlcb(alpm_handle_t *handle) { CHECK_HANDLE(handle, return NULL); @@ -258,13 +252,6 @@ int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle) return handle->checkspace; } -int SYMEXPORT alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb) -{ - CHECK_HANDLE(handle, return -1); - handle->logcb = cb; - return 0; -} - int SYMEXPORT alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb) { CHECK_HANDLE(handle, return -1); diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 4275d13..1637d9d 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -64,7 +64,6 @@ struct __alpm_handle_t { #endif /* callback functions */ - alpm_cb_log logcb; /* Log callback function */ alpm_cb_download dlcb; /* Download callback function */ alpm_cb_totaldl totaldlcb; /* Total download callback function */ alpm_cb_fetch fetchcb; /* Download file callback function */ diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index 271bd00..d86325d 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -74,15 +74,19 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix, void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...) { - va_list args; + alpm_event_log_t event = { + .type = ALPM_EVENT_LOG, + .level = flag, + .fmt = fmt + }; - if(handle == NULL || handle->logcb == NULL) { + if(handle == NULL || handle->eventcb == NULL) { return; } - va_start(args, fmt); - handle->logcb(flag, fmt, args); - va_end(args); + va_start(event.args, fmt); + EVENT(handle, &event); + va_end(event.args); } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 040c2bd..af1c99d 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -270,6 +270,24 @@ void cb_event(alpm_event_t *event) ((alpm_event_database_missing_t *) event)->dbname); } break; + case ALPM_EVENT_LOG: + { + alpm_event_log_t *e = (alpm_event_log_t *) event; + if(!e->fmt || strlen(e->fmt) == 0) { + break; + } + + if(on_progress) { + char *string = NULL; + pm_vasprintf(&string, e->level, e->fmt, e->args); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_vfprintf(stderr, e->level, e->fmt, e->args); + } + } + break; /* all the simple done events, with fallthrough for each */ case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: @@ -776,22 +794,4 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) return; } -/* Callback to handle notifications from the library */ -void cb_log(alpm_loglevel_t level, const char *fmt, va_list args) -{ - if(!fmt || strlen(fmt) == 0) { - return; - } - - if(on_progress) { - char *string = NULL; - pm_vasprintf(&string, level, fmt, args); - if(string != NULL) { - output = alpm_list_add(output, string); - } - } else { - pm_vfprintf(stderr, level, fmt, args); - } -} - /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/callback.h b/src/pacman/callback.h index b19b952..80d3d63 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -40,10 +40,6 @@ void cb_dl_total(off_t total); /* callback to handle display of download progress */ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total); -/* callback to handle messages/notifications from pacman library */ -__attribute__((format(printf, 2, 0))) -void cb_log(alpm_loglevel_t level, const char *fmt, va_list args); - #endif /* _PM_CALLBACK_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index cf8a417..c00e0ac 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -675,7 +675,6 @@ static int setup_libalpm(void) } config->handle = handle; - alpm_option_set_logcb(handle, cb_log); alpm_option_set_dlcb(handle, cb_dl_progress); alpm_option_set_eventcb(handle, cb_event); alpm_option_set_questioncb(handle, cb_question); diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index b13d770..e7530e4 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -35,17 +35,19 @@ static void cleanup(int signum) exit(signum); } -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) +static void output_cb(alpm_event_log_t *event) { - if(strlen(fmt)) { - switch(level) { + if(event->type != ALPM_EVENT_LOG) { + return; + } + if(strlen(event->fmt)) { + switch(event->level) { case ALPM_LOG_ERROR: printf("error: "); break; case ALPM_LOG_WARNING: printf("warning: "); break; /* case ALPM_LOG_DEBUG: printf("debug: "); break; */ default: return; } - vprintf(fmt, args); + vprintf(event->fmt, event->args); } } @@ -126,7 +128,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); + alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb); checkdbs(dbnames); alpm_list_free(dbnames); diff --git a/src/util/testdb.c b/src/util/testdb.c index 3d341b3..c84d9e0 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -38,16 +38,18 @@ static void cleanup(int signum) exit(signum); } -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) +static void output_cb(alpm_event_log_t *event) { - if(strlen(fmt)) { - switch(level) { + if(event->type != ALPM_EVENT_LOG) { + return; + } + if(strlen(event->fmt)) { + switch(event->level) { case ALPM_LOG_ERROR: printf("error: "); break; case ALPM_LOG_WARNING: printf("warning: "); break; default: return; } - vprintf(fmt, args); + vprintf(event->fmt, event->args); } } @@ -281,7 +283,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); + alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb); if(!dbnames) { errors = check_localdb(); diff --git a/src/util/testpkg.c b/src/util/testpkg.c index d1b75ac..8cf380b 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -22,18 +22,20 @@ #include <alpm.h> -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) +static void output_cb(alpm_event_log_t *event) { - if(fmt[0] == '\0') { + if(event->type != ALPM_EVENT_LOG) { return; } - switch(level) { + if(event->fmt[0] == '\0') { + return; + } + switch(event->level) { case ALPM_LOG_ERROR: printf("error: "); break; case ALPM_LOG_WARNING: printf("warning: "); break; default: return; /* skip other messages */ } - vprintf(fmt, args); + vprintf(event->fmt, event->args); } int main(int argc, char *argv[]) @@ -58,7 +60,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); + alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb); /* set gpgdir to default */ alpm_option_set_gpgdir(handle, GPGDIR); -- 1.8.4.2
On 03/12/13 06:45, Olivier Brunel wrote:
When ALPM emits a log message, it still goes through _alpm_log() but instead of calling a specific log callback, it goes as an event.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
Looks fine to me. Allan
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 41 +++++++++++++++++++++++++++++++++++------ lib/libalpm/alpm.h | 41 ++++++++++++++++++++++++++++++++++++++++- lib/libalpm/remove.c | 7 ++++++- src/pacman/callback.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/util.c | 13 +++++++++++++ src/pacman/util.h | 1 + 6 files changed, 143 insertions(+), 8 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 3067df5..50e35a6 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -363,8 +363,14 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, newpath)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"), - filename, newpath); + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 0, + .oldpkg = oldpkg, + .newpkg = newpkg, + .oldfile = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s installed as %s\n", filename, newpath); } @@ -391,8 +397,12 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, filename)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, - _("%s saved as %s\n"), filename, newpath); + alpm_event_pacorig_created_t event = { + .type = ALPM_EVENT_PACORIG_CREATED, + .newpkg = newpkg, + .oldfile = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", filename, newpath); } @@ -407,14 +417,16 @@ needbackup_cleanup: free(hash_local); free(hash_pkg); } else { + size_t len; /* we didn't need a backup */ if(notouch) { /* change the path to a .pacnew extension */ _alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename); - _alpm_log(handle, ALPM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: extracting %s as %s.pacnew\n", filename, filename); - strncat(filename, ".pacnew", PATH_MAX - strlen(filename)); + /* remember len so we can get the old filename back for the event */ + len = strlen(filename); + strncat(filename, ".pacnew", PATH_MAX - len); } else { _alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename); } @@ -433,6 +445,23 @@ needbackup_cleanup: return errors; } + if(notouch) { + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 1, + .oldpkg = oldpkg, + .newpkg = newpkg, + .oldfile = filename + }; + /* "remove" the .pacnew suffix */ + if(len < PATH_MAX) + filename[len] = '\0'; + EVENT(handle, &event); + /* restore */ + if(len < PATH_MAX) + filename[len] = '.'; + } + /* calculate an hash if this is in newpkg's backup */ alpm_list_t *i; for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) { diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index bf11e41..2f8d6d5 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -337,7 +337,15 @@ typedef enum _alpm_event_type_t { /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE, /** A log message was emitted; See alpm_event_log_t for arguments. */ - ALPM_EVENT_LOG + ALPM_EVENT_LOG, + /** A .pacnew file was created; See alpm_event_pacnew_created_t for arguments. */ + ALPM_EVENT_PACNEW_CREATED, + /** A .pacsave file was created; See alpm_event_pacsave_created_t for + * arguments */ + ALPM_EVENT_PACSAVE_CREATED, + /** A .pacorig file was created; See alpm_event_pacorig_created_t for + * arguments */ + ALPM_EVENT_PACORIG_CREATED } alpm_event_type_t; /** Events. @@ -424,6 +432,37 @@ typedef struct _alpm_event_log_t { va_list args; } alpm_event_log_t; +typedef struct _alpm_event_pacnew_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Whether the creation was result of a NoUpgrade or not */ + int from_noupgrade; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New Package. */ + alpm_pkg_t *newpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacnew_created_t; + +typedef struct _alpm_event_pacsave_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacsave_created_t; + +typedef struct _alpm_event_pacorig_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** New package. */ + alpm_pkg_t *newpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacorig_created_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 32d71ab..f6dc99b 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -526,6 +526,11 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, int cmp = filehash ? strcmp(filehash, backup->hash) : 0; FREE(filehash); if(cmp != 0) { + alpm_event_pacsave_created_t event = { + .type = ALPM_EVENT_PACSAVE_CREATED, + .oldpkg = oldpkg, + .oldfile = file + }; char *newpath; size_t len = strlen(file) + 8 + 1; MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); @@ -540,7 +545,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, free(newpath); return -1; } - _alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", file, newpath); free(newpath); diff --git a/src/pacman/callback.c b/src/pacman/callback.c index af1c99d..c881b69 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -288,6 +288,54 @@ void cb_event(alpm_event_t *event) } } break; + case ALPM_EVENT_PACNEW_CREATED: + { + alpm_event_pacnew_created_t *e = (alpm_event_pacnew_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"), + e->oldfile, e->oldfile); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"), + e->oldfile, e->oldfile); + } + } + break; + case ALPM_EVENT_PACSAVE_CREATED: + { + alpm_event_pacsave_created_t *e = (alpm_event_pacsave_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"), + e->oldfile, e->oldfile); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"), + e->oldfile, e->oldfile); + } + } + break; + case ALPM_EVENT_PACORIG_CREATED: + { + alpm_event_pacorig_created_t *e = (alpm_event_pacorig_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"), + e->oldfile, e->oldfile); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"), + e->oldfile, e->oldfile); + } + } + break; /* all the simple done events, with fallthrough for each */ case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: diff --git a/src/pacman/util.c b/src/pacman/util.c index 4877cc3..ccec4b8 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1577,6 +1577,19 @@ int pm_asprintf(char **string, const char *format, ...) return ret; } +int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) +{ + int ret = 0; + va_list args; + + /* print the message using va_arg list */ + va_start(args, format); + ret = pm_vasprintf(string, level, format, args); + va_end(args); + + return ret; +} + int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) { int ret = 0; diff --git a/src/pacman/util.h b/src/pacman/util.h index e2297f8..0e85caa 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -78,6 +78,7 @@ int noyes(const char *format, ...) __attribute__((format(printf, 1, 2))); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3))); int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); +int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); #endif /* _PM_UTIL_H */ -- 1.8.4.2
To go along with RETRIEVE_START, one other event will be emmitted once the downloads are done: RETRIEVE_DONE if all files were successfully downloaded, else RETRIEVE_FAILED. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 4 ++++ lib/libalpm/sync.c | 3 +++ src/pacman/callback.c | 2 ++ 3 files changed, 9 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 2f8d6d5..a61a712 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -318,6 +318,10 @@ typedef enum _alpm_event_type_t { ALPM_EVENT_SCRIPTLET_INFO, /** Files will be downloaded from a repository. */ ALPM_EVENT_RETRIEVE_START, + /** Files were downloaded from a repository. */ + ALPM_EVENT_RETRIEVE_DONE, + /** Not all files were successfully downloaded from a repository. */ + ALPM_EVENT_RETRIEVE_FAILED, /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, /** Disk space usage was computed for a package. */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index c79000c..8046ce5 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -974,12 +974,15 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) event.type = ALPM_EVENT_RETRIEVE_START; EVENT(handle, &event); + event.type = ALPM_EVENT_RETRIEVE_DONE; for(i = files; i; i = i->next) { if(download_single_file(handle, i->data, cachedir) == -1) { errors++; + event.type = ALPM_EVENT_RETRIEVE_FAILED; _alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n")); } } + EVENT(handle, &event); } finish: diff --git a/src/pacman/callback.c b/src/pacman/callback.c index c881b69..e4517f8 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -348,6 +348,8 @@ void cb_event(alpm_event_t *event) case ALPM_EVENT_DELTA_INTEGRITY_DONE: case ALPM_EVENT_DELTA_PATCHES_DONE: case ALPM_EVENT_DISKSPACE_DONE: + case ALPM_EVENT_RETRIEVE_DONE: + case ALPM_EVENT_RETRIEVE_FAILED: /* nothing */ break; } -- 1.8.4.2
These will be emmitted when download a package file from a repository, indicating that the download starts, and whether it was successfull or not. Note that when multiple servers are available, no event is emmitted when switching to another server. (This doesn't apply to alpm_fetch_pkgurl(), but since it is called by the frontend, it shouldn't have problems knowing when the download starts and when it ends.) Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 16 ++++++++++++++++ lib/libalpm/sync.c | 9 +++++++++ src/pacman/callback.c | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index a61a712..f146ab1 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -322,6 +322,15 @@ typedef enum _alpm_event_type_t { ALPM_EVENT_RETRIEVE_DONE, /** Not all files were successfully downloaded from a repository. */ ALPM_EVENT_RETRIEVE_FAILED, + /** A file will be downloaded from a repository; See alpm_event_pkgdownload_t + * for arguments */ + ALPM_EVENT_PKGDOWNLOAD_START, + /** A file was downloaded from a repository; See alpm_event_pkgdownload_t + * for arguments */ + ALPM_EVENT_PKGDOWNLOAD_DONE, + /** A file failed to be downloaded from a repository; See + * alpm_event_pkgdownload_t for arguments */ + ALPM_EVENT_PKGDOWNLOAD_FAILED, /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, /** Disk space usage was computed for a package. */ @@ -467,6 +476,13 @@ typedef struct _alpm_event_pacorig_created_t { const char *oldfile; } alpm_event_pacorig_created_t; +typedef struct _alpm_event_pkgdownload_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the file */ + const char *file; +} alpm_event_pkgdownload_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 8046ce5..3ed10c0 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -894,11 +894,16 @@ static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t static int download_single_file(alpm_handle_t *handle, struct dload_payload *payload, const char *cachedir) { + alpm_event_pkgdownload_t event = { + .type = ALPM_EVENT_PKGDOWNLOAD_START, + .file = payload->remote_name + }; const alpm_list_t *server; payload->handle = handle; payload->allow_resume = 1; + EVENT(handle, &event); for(server = payload->servers; server; server = server->next) { const char *server_url = server->data; size_t len; @@ -909,6 +914,8 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name); if(_alpm_download(payload, cachedir, NULL, NULL) != -1) { + event.type = ALPM_EVENT_PKGDOWNLOAD_DONE; + EVENT(handle, &event); return 0; } @@ -916,6 +923,8 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay payload->unlink_on_fail = 0; } + event.type = ALPM_EVENT_PKGDOWNLOAD_FAILED; + EVENT(handle, &event); return -1; } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index e4517f8..2a89d30 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -350,6 +350,10 @@ void cb_event(alpm_event_t *event) case ALPM_EVENT_DISKSPACE_DONE: case ALPM_EVENT_RETRIEVE_DONE: case ALPM_EVENT_RETRIEVE_FAILED: + /* we can safely ignore those as well */ + case ALPM_EVENT_PKGDOWNLOAD_START: + case ALPM_EVENT_PKGDOWNLOAD_DONE: + case ALPM_EVENT_PKGDOWNLOAD_FAILED: /* nothing */ break; } -- 1.8.4.2
Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- src/pacman/callback.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 506692f..8c0fab5 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -528,10 +528,11 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, if(percent == 100) { alpm_list_t *i = NULL; on_progress = 0; + fflush(stdout); for(i = output; i; i = i->next) { - fputs((const char *)i->data, stdout); + fputs((const char *)i->data, stderr); } - fflush(stdout); + fflush(stderr); FREELIST(output); } else { on_progress = 1; -- 1.8.5.2
Because this event is triggered when an optdepend for another package is being removed. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 2 +- lib/libalpm/remove.c | 2 +- src/pacman/callback.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 5628527..126f50a5 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -377,7 +377,7 @@ typedef enum _alpm_event_t { 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_OPTDEP_REMOVAL, /** A configured repository database is missing */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 899952b..d78c5f1 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,7 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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); + EVENT(handle, ALPM_EVENT_OPTDEP_REMOVAL, pkg, optdep); } } } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 8c0fab5..4b0f881 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -247,7 +247,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("checking available disk space...\n")); } break; - case ALPM_EVENT_OPTDEP_REQUIRED: + case ALPM_EVENT_OPTDEP_REMOVAL: colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), alpm_dep_compute_string(data2)); break; -- 1.8.5.2
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered. With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 31 ++++++----- lib/libalpm/alpm.h | 148 +++++++++++++++++++++++++++++--------------------- lib/libalpm/be_sync.c | 6 +- lib/libalpm/handle.h | 4 +- lib/libalpm/remove.c | 25 +++++++-- lib/libalpm/sync.c | 81 +++++++++++++++++++-------- lib/libalpm/util.c | 6 +- src/pacman/callback.c | 87 ++++++++++++++++------------- src/pacman/callback.h | 2 +- 9 files changed, 241 insertions(+), 149 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 91b40a1..1eaea36 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -460,7 +460,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; alpm_progress_t progress = ALPM_PROGRESS_ADD_START; - alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; + alpm_event_package_operation_t event; const char *log_msg = "adding"; const char *pkgfile; @@ -473,18 +473,15 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, if(cmp < 0) { log_msg = "downgrading"; progress = ALPM_PROGRESS_DOWNGRADE_START; - start = ALPM_EVENT_DOWNGRADE_START; - done = ALPM_EVENT_DOWNGRADE_DONE; + event.operation = ALPM_PACKAGE_DOWNGRADE; } else if(cmp == 0) { log_msg = "reinstalling"; progress = ALPM_PROGRESS_REINSTALL_START; - start = ALPM_EVENT_REINSTALL_START; - done = ALPM_EVENT_REINSTALL_DONE; + event.operation = ALPM_PACKAGE_REINSTALL; } else { log_msg = "upgrading"; progress = ALPM_PROGRESS_UPGRADE_START; - start = ALPM_EVENT_UPGRADE_START; - done = ALPM_EVENT_UPGRADE_DONE; + event.operation = ALPM_PACKAGE_UPGRADE; } is_upgrade = 1; @@ -496,9 +493,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, /* copy over the install reason */ newpkg->reason = alpm_pkg_get_reason(local); + } else { + event.operation = ALPM_PACKAGE_INSTALL; } - EVENT(handle, start, newpkg, local); + event.type = ALPM_EVENT_PACKAGE_OPERATION_START; + event.oldpkg = oldpkg; + event.newpkg = newpkg; + EVENT(handle, &event); pkgfile = newpkg->origin_data.file; @@ -649,20 +651,20 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current); - switch(done) { - case ALPM_EVENT_ADD_DONE: + switch(event.operation) { + case ALPM_PACKAGE_INSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "installed %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_DOWNGRADE_DONE: + case ALPM_PACKAGE_DOWNGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "downgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; - case ALPM_EVENT_REINSTALL_DONE: + case ALPM_PACKAGE_REINSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "reinstalled %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_UPGRADE_DONE: + case ALPM_PACKAGE_UPGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "upgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; @@ -682,7 +684,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, free(scriptlet); } - EVENT(handle, done, newpkg, oldpkg); + event.type = ALPM_EVENT_PACKAGE_OPERATION_DONE; + EVENT(handle, &event); cleanup: _alpm_pkg_free(oldpkg); diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 126f50a5..9379372 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -275,10 +275,9 @@ int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4))); /** - * Events. - * NULL parameters are passed to in all events unless specified otherwise. + * Type of events. */ -typedef enum _alpm_event_t { +typedef enum _alpm_event_type_t { /** Dependencies will be computed for a package. */ ALPM_EVENT_CHECKDEPS_START = 1, /** Dependencies were computed for a package. */ @@ -295,49 +294,12 @@ typedef enum _alpm_event_t { ALPM_EVENT_INTERCONFLICTS_START, /** Inter-conflicts were checked for target package. */ ALPM_EVENT_INTERCONFLICTS_DONE, - /** Package will be installed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_ADD_START, - /** Package was installed. - * A pointer to the new package is passed to the callback. - */ - ALPM_EVENT_ADD_DONE, - /** Package will be removed. - * A pointer to the target package is passed to the callback. - */ - ALPM_EVENT_REMOVE_START, - /** Package was removed. - * A pointer to the removed package is passed to the callback. - */ - ALPM_EVENT_REMOVE_DONE, - /** Package will be upgraded. - * A pointer to the upgraded package is passed to the callback. - */ - ALPM_EVENT_UPGRADE_START, - /** Package was upgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_UPGRADE_DONE, - /** Package will be downgraded. - * A pointer to the downgraded package is passed to the callback. - */ - ALPM_EVENT_DOWNGRADE_START, - /** Package was downgraded. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_DOWNGRADE_DONE, - /** Package will be reinstalled. - * A pointer to the reinstalled package is passed to the callback. - */ - ALPM_EVENT_REINSTALL_START, - /** Package was reinstalled. - * A pointer to the new package, and a pointer to the old package is passed - * to the callback, respectively. - */ - ALPM_EVENT_REINSTALL_DONE, + /** Package will be installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_package_operation_t for arguments. */ + ALPM_EVENT_PACKAGE_OPERATION_START, + /** Package was installed/upgraded/downgraded/re-installed/removed; See + * alpm_event_package_operation_t for arguments. */ + ALPM_EVENT_PACKAGE_OPERATION_DONE, /** Target package's integrity will be checked. */ ALPM_EVENT_INTEGRITY_START, /** Target package's integrity was checked. */ @@ -354,31 +316,27 @@ typedef enum _alpm_event_t { ALPM_EVENT_DELTA_PATCHES_START, /** Deltas were applied to packages. */ ALPM_EVENT_DELTA_PATCHES_DONE, - /** Delta patch will be applied to target package. - * The filename of the package and the filename of the patch is passed to the - * callback. - */ + /** Delta patch will be applied to target package; See + * alpm_event_delta_patch_t for arguments.. */ ALPM_EVENT_DELTA_PATCH_START, /** Delta patch was applied to target package. */ ALPM_EVENT_DELTA_PATCH_DONE, /** Delta patch failed to apply to target package. */ ALPM_EVENT_DELTA_PATCH_FAILED, - /** Scriptlet has printed information. - * A line of text is passed to the callback. - */ + /** Scriptlet has printed information; See alpm_event_scriptlet_info_t for + * arguments. */ ALPM_EVENT_SCRIPTLET_INFO, - /** Files will be downloaded from a repository. - * The repository's tree name is passed to the callback. - */ + /** Files will be downloaded from a repository. */ ALPM_EVENT_RETRIEVE_START, - /** Disk space usage will be computed for a package */ + /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, - /** Disk space usage was computed for a package */ + /** Disk space usage was computed for a package. */ ALPM_EVENT_DISKSPACE_DONE, - /** An optdepend for another package is being removed - * The requiring package and its dependency are passed to the callback */ + /** An optdepend for another package is being removed; See + * alpm_event_optdep_removal_t for arguments. */ ALPM_EVENT_OPTDEP_REMOVAL, - /** A configured repository database is missing */ + /** A configured repository database is missing; See + * alpm_event_database_missing_t for arguments. */ ALPM_EVENT_DATABASE_MISSING, /** Checking keys used to create signatures are in keyring. */ ALPM_EVENT_KEYRING_START, @@ -388,10 +346,74 @@ typedef enum _alpm_event_t { ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE +} alpm_event_type_t; + +/** Events. + * This is a generic struct this is passed to the callback, that allows the + * frontend to know which type of event was triggered. It is then possible to + * typecast the pointer to the right structure, in order to access + * event-specific data. */ +typedef struct _alpm_event_t { + /** Type of event. */ + alpm_event_type_t type; } alpm_event_t; -/** Event callback */ -typedef void (*alpm_cb_event)(alpm_event_t, void *, void *); +typedef enum _alpm_package_operation_t { + /** Package (to be) installed. (No oldpkg) */ + ALPM_PACKAGE_INSTALL = 1, + /** Package (to be) upgraded */ + ALPM_PACKAGE_UPGRADE, + /** Package (to be) re-installed. */ + ALPM_PACKAGE_REINSTALL, + /** Package (to be) downgraded. */ + ALPM_PACKAGE_DOWNGRADE, + /** Package (to be) removed. (No newpkg) */ + ALPM_PACKAGE_REMOVE +} alpm_package_operation_t; + +typedef struct _alpm_event_package_operation_t { + /** Type of event. */ + alpm_event_type_t type; + /** Type of operation. */ + alpm_package_operation_t operation; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New package. */ + alpm_pkg_t *newpkg; +} alpm_event_package_operation_t; + +typedef struct _alpm_event_optdep_removal_t { + /** Type of event. */ + alpm_event_type_t type; + /** Package with the optdep. */ + alpm_pkg_t *pkg; + /** Optdep being removed. */ + alpm_depend_t *optdep; +} alpm_event_optdep_removal_t; + +typedef struct _alpm_event_delta_patch_t { + /** Type of event. */ + alpm_event_type_t type; + /** Delta info */ + alpm_delta_t *delta; +} alpm_event_delta_patch_t; + +typedef struct _alpm_event_scriptlet_info_t { + /** Type of event. */ + alpm_event_type_t type; + /** Line of scriptlet output. */ + const char *line; +} alpm_event_scriptlet_info_t; + +typedef struct _alpm_event_database_missing_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the database. */ + const char *dbname; +} alpm_event_database_missing_t; + +/** Event callback. */ +typedef void (*alpm_cb_event)(alpm_event_t *); /** * Questions. diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 67b7368..922b3a2 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -89,9 +89,13 @@ static int sync_db_validate(alpm_db_t *db) /* we can skip any validation if the database doesn't exist */ if(_alpm_access(db->handle, NULL, dbpath, R_OK) != 0 && errno == ENOENT) { + alpm_event_database_missing_t event = { + .type = ALPM_EVENT_DATABASE_MISSING, + .dbname = db->treename + }; db->status &= ~DB_STATUS_EXISTS; db->status |= DB_STATUS_MISSING; - EVENT(db->handle, ALPM_EVENT_DATABASE_MISSING, db->treename, NULL); + EVENT(db->handle, &event); goto valid; } db->status |= DB_STATUS_EXISTS; diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index fcfd4fa..d767fb6 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -31,10 +31,10 @@ #include <curl/curl.h> #endif -#define EVENT(h, e, d1, d2) \ +#define EVENT(h, e) \ do { \ if((h)->eventcb) { \ - (h)->eventcb(e, d1, d2); \ + (h)->eventcb((alpm_event_t *) (e)); \ } \ } while(0) #define QUESTION(h, q, d1, d2, d3, r) \ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index d78c5f1..c2831e4 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -179,7 +179,12 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * 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_REMOVAL, pkg, optdep); + alpm_event_optdep_removal_t event = { + .type = ALPM_EVENT_OPTDEP_REMOVAL, + .pkg = pkg, + .optdep = optdep + }; + EVENT(handle, &event); } } } @@ -203,6 +208,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_t *lp; alpm_trans_t *trans = handle->trans; alpm_db_t *db = handle->db_local; + alpm_event_t event; if((trans->flags & ALPM_TRANS_FLAG_RECURSE) && !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) { @@ -214,7 +220,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) } if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1); @@ -254,7 +261,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) remove_notify_needed_optdepends(handle, trans->remove); if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { - EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_CHECKDEPS_DONE; + EVENT(handle, &event); } return 0; @@ -656,12 +664,18 @@ int _alpm_remove_single_package(alpm_handle_t *handle, { const char *pkgname = oldpkg->name; const char *pkgver = oldpkg->version; + alpm_event_package_operation_t event = { + .type = ALPM_EVENT_PACKAGE_OPERATION_START, + .operation = ALPM_PACKAGE_REMOVE, + .oldpkg = oldpkg, + .newpkg = NULL + }; if(newpkg) { _alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n", pkgname, pkgver); } else { - EVENT(handle, ALPM_EVENT_REMOVE_START, oldpkg, NULL); + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n", pkgname, pkgver); @@ -695,7 +709,8 @@ int _alpm_remove_single_package(alpm_handle_t *handle, } if(!newpkg) { - EVENT(handle, ALPM_EVENT_REMOVE_DONE, oldpkg, NULL); + event.type = ALPM_EVENT_PACKAGE_OPERATION_DONE; + EVENT(handle, &event); } /* remove the package from the database */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 4ae01ac..63adba4 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -374,6 +374,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) size_t from_sync = 0; int ret = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event; if(data) { *data = NULL; @@ -403,7 +404,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) /* Build up list by repeatedly resolving each transaction package */ /* Resolve targets dependencies */ - EVENT(handle, ALPM_EVENT_RESOLVEDEPS_START, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n"); /* build remove list for resolvedeps */ @@ -479,12 +481,14 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_list_free(trans->add); trans->add = resolved; - EVENT(handle, ALPM_EVENT_RESOLVEDEPS_DONE, NULL, NULL); + event.type = ALPM_EVENT_RESOLVEDEPS_DONE; + EVENT(handle, &event); } if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) { /* check for inter-conflicts and whatnot */ - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n"); @@ -594,7 +598,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) goto cleanup; } } - EVENT(handle, ALPM_EVENT_INTERCONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTERCONFLICTS_DONE; + EVENT(handle, &event); alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free); alpm_list_free(deps); } @@ -678,6 +683,7 @@ static int apply_deltas(alpm_handle_t *handle) int deltas_found = 0, ret = 0; const char *cachedir = _alpm_filecache_setup(handle); alpm_trans_t *trans = handle->trans; + alpm_event_delta_patch_t event; for(i = trans->add; i; i = i->next) { alpm_pkg_t *spkg = i->data; @@ -691,7 +697,8 @@ static int apply_deltas(alpm_handle_t *handle) if(!deltas_found) { /* only show this if we actually have deltas to apply, and it is before * the very first one */ - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_START; + EVENT(handle, &event); deltas_found = 1; } @@ -725,11 +732,14 @@ static int apply_deltas(alpm_handle_t *handle) _alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command); - EVENT(handle, ALPM_EVENT_DELTA_PATCH_START, d->to, d->delta); + event.type = ALPM_EVENT_DELTA_PATCH_START; + event.delta = d; + EVENT(handle, &event); int retval = system(command); if(retval == 0) { - EVENT(handle, ALPM_EVENT_DELTA_PATCH_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_DONE; + EVENT(handle, &event); /* delete the delta file */ unlink(delta); @@ -747,7 +757,8 @@ static int apply_deltas(alpm_handle_t *handle) if(retval != 0) { /* one delta failed for this package, cancel the remaining ones */ - EVENT(handle, ALPM_EVENT_DELTA_PATCH_FAILED, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCH_FAILED; + EVENT(handle, &event); handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED; ret = 1; break; @@ -755,7 +766,8 @@ static int apply_deltas(alpm_handle_t *handle) } } if(deltas_found) { - EVENT(handle, ALPM_EVENT_DELTA_PATCHES_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_PATCHES_DONE; + EVENT(handle, &event); } return ret; @@ -784,13 +796,15 @@ static int prompt_to_delete(alpm_handle_t *handle, const char *filepath, static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) { alpm_list_t *i, *errors = NULL; + alpm_event_t event; if(!deltas) { return 0; } /* Check integrity of deltas */ - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_START; + EVENT(handle, &event); for(i = deltas; i; i = i->next) { alpm_delta_t *d = i->data; char *filepath = _alpm_filecache_find(handle, d->delta); @@ -801,7 +815,8 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas) FREE(filepath); } } - EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_DELTA_INTEGRITY_DONE; + EVENT(handle, &event); if(errors) { for(i = errors; i; i = i->next) { @@ -907,6 +922,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) const char *cachedir; alpm_list_t *i, *files = NULL; int errors = 0; + alpm_event_t event; cachedir = _alpm_filecache_setup(handle); handle->trans->state = STATE_DOWNLOADING; @@ -954,7 +970,8 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) } } - EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL); + event.type = ALPM_EVENT_RETRIEVE_START; + EVENT(handle, &event); for(i = files; i; i = i->next) { if(download_single_file(handle, i->data, cachedir) == -1) { errors++; @@ -988,8 +1005,10 @@ static int check_keyring(alpm_handle_t *handle) { size_t current = 0, numtargs; alpm_list_t *i, *errors = NULL; + alpm_event_t event; - EVENT(handle, ALPM_EVENT_KEYRING_START, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_START; + EVENT(handle, &event); numtargs = alpm_list_count(handle->trans->add); @@ -1033,10 +1052,12 @@ static int check_keyring(alpm_handle_t *handle) PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", 100, numtargs, current); - EVENT(handle, ALPM_EVENT_KEYRING_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEYRING_DONE; + EVENT(handle, &event); if(errors) { - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_START, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_START; + EVENT(handle, &event); int fail = 0; alpm_list_t *k; for(k = errors; k; k = k->next) { @@ -1045,7 +1066,8 @@ static int check_keyring(alpm_handle_t *handle) fail = 1; } } - EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_KEY_DOWNLOAD_DONE; + EVENT(handle, &event); if(fail) { _alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n")); return -1; @@ -1070,9 +1092,11 @@ static int check_validity(alpm_handle_t *handle, size_t current = 0; uint64_t current_bytes = 0; alpm_list_t *i, *errors = NULL; + alpm_event_t event; /* Check integrity of packages */ - EVENT(handle, ALPM_EVENT_INTEGRITY_START, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_START; + EVENT(handle, &event); for(i = handle->trans->add; i; i = i->next, current++) { struct validity v = { i->data, NULL, NULL, 0, 0, 0 }; @@ -1104,7 +1128,8 @@ static int check_validity(alpm_handle_t *handle, PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL); + event.type = ALPM_EVENT_INTEGRITY_DONE; + EVENT(handle, &event); if(errors) { for(i = errors; i; i = i->next) { @@ -1143,9 +1168,11 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, size_t current = 0, current_bytes = 0; int errors = 0; alpm_list_t *i; + alpm_event_t event; /* load packages from disk now that they are known-valid */ - EVENT(handle, ALPM_EVENT_LOAD_START, NULL, NULL); + event.type = ALPM_EVENT_LOAD_START; + EVENT(handle, &event); for(i = handle->trans->add; i; i = i->next, current++) { alpm_pkg_t *spkg = i->data; @@ -1186,7 +1213,8 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100, total, current); - EVENT(handle, ALPM_EVENT_LOAD_DONE, NULL, NULL); + event.type = ALPM_EVENT_LOAD_DONE; + EVENT(handle, &event); if(errors) { if(!handle->pm_errno) { @@ -1204,6 +1232,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) size_t total = 0; uint64_t total_bytes = 0; alpm_trans_t *trans = handle->trans; + alpm_event_t event; if(download_files(handle, &deltas)) { alpm_list_free(deltas); @@ -1262,7 +1291,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) /* fileconflict check */ if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_FILECONFLICTS_START, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n"); alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle, @@ -1277,12 +1307,14 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1); } - EVENT(handle, ALPM_EVENT_FILECONFLICTS_DONE, NULL, NULL); + event.type = ALPM_EVENT_FILECONFLICTS_DONE; + EVENT(handle, &event); } /* check available disk space */ if(handle->checkspace && !(trans->flags & ALPM_TRANS_FLAG_DBONLY)) { - EVENT(handle, ALPM_EVENT_DISKSPACE_START, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_START; + EVENT(handle, &event); _alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n"); if(_alpm_check_diskspace(handle) == -1) { @@ -1290,7 +1322,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) return -1; } - EVENT(handle, ALPM_EVENT_DISKSPACE_DONE, NULL, NULL); + event.type = ALPM_EVENT_DISKSPACE_DONE; + EVENT(handle, &event); } /* remove conflicting and to-be-replaced packages */ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index f28404d..7704ea5 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -572,10 +572,14 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]) } else { while(!feof(pipe_file)) { char line[PATH_MAX]; + alpm_event_scriptlet_info_t event = { + .type = ALPM_EVENT_SCRIPTLET_INFO, + .line = line + }; if(fgets(line, PATH_MAX, pipe_file) == NULL) break; alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line); - EVENT(handle, ALPM_EVENT_SCRIPTLET_INFO, line, NULL); + EVENT(handle, &event); } fclose(pipe_file); } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 4b0f881..8b67ffc 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -149,12 +149,12 @@ static void fill_progress(const int bar_percent, const int disp_percent, } /* callback to handle messages/notifications from libalpm transactions */ -void cb_event(alpm_event_t event, void *data1, void *data2) +void cb_event(alpm_event_t *event) { if(config->print) { return; } - switch(event) { + switch(event->type) { case ALPM_EVENT_CHECKDEPS_START: printf(_("checking dependencies...\n")); break; @@ -169,38 +169,43 @@ void cb_event(alpm_event_t event, void *data1, void *data2) case ALPM_EVENT_INTERCONFLICTS_START: printf(_("looking for conflicting packages...\n")); break; - case ALPM_EVENT_ADD_START: - if(config->noprogressbar) { - printf(_("installing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_ADD_DONE: - display_optdepends(data1); - break; - case ALPM_EVENT_REMOVE_START: + case ALPM_EVENT_PACKAGE_OPERATION_START: if(config->noprogressbar) { - printf(_("removing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_START: - if(config->noprogressbar) { - printf(_("upgrading %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_DOWNGRADE_START: - if(config->noprogressbar) { - printf(_("downgrading %s...\n"), alpm_pkg_get_name(data1)); + alpm_event_package_operation_t *e = (alpm_event_package_operation_t *) event; + switch(e->operation) { + case ALPM_PACKAGE_INSTALL: + printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_UPGRADE: + printf(_("upgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_REINSTALL: + printf(_("reinstalling %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_DOWNGRADE: + printf(_("downgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_REMOVE: + printf(_("removing %s...\n"), alpm_pkg_get_name(e->oldpkg)); + break; + } } break; - case ALPM_EVENT_DOWNGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_REINSTALL_START: - if(config->noprogressbar) { - printf(_("reinstalling %s...\n"), alpm_pkg_get_name(data1)); + case ALPM_EVENT_PACKAGE_OPERATION_DONE: + { + alpm_event_package_operation_t *e = (alpm_event_package_operation_t *) event; + switch(e->operation) { + case ALPM_PACKAGE_INSTALL: + display_optdepends(e->newpkg); + break; + case ALPM_PACKAGE_UPGRADE: + case ALPM_PACKAGE_DOWNGRADE: + display_new_optdepends(e->oldpkg, e->newpkg); + break; + case ALPM_PACKAGE_REINSTALL: + case ALPM_PACKAGE_REMOVE: + break; + } } break; case ALPM_EVENT_INTEGRITY_START: @@ -228,7 +233,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("applying deltas...\n")); break; case ALPM_EVENT_DELTA_PATCH_START: - printf(_("generating %s with %s... "), (char *)data1, (char *)data2); + { + alpm_event_delta_patch_t *e = (alpm_event_delta_patch_t *) event; + printf(_("generating %s with %s... "), e->delta->to, e->delta->delta); + } break; case ALPM_EVENT_DELTA_PATCH_DONE: printf(_("success!\n")); @@ -237,7 +245,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("failed.\n")); break; case ALPM_EVENT_SCRIPTLET_INFO: - fputs((const char *)data1, stdout); + fputs(((alpm_event_scriptlet_info_t *) event)->line, stdout); break; case ALPM_EVENT_RETRIEVE_START: colon_printf(_("Retrieving packages ...\n")); @@ -248,18 +256,21 @@ void cb_event(alpm_event_t event, void *data1, void *data2) } break; case ALPM_EVENT_OPTDEP_REMOVAL: - colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), - alpm_dep_compute_string(data2)); + { + alpm_event_optdep_removal_t *e = (alpm_event_optdep_removal_t *) event; + colon_printf(_("%s optionally requires %s\n"), + alpm_pkg_get_name(e->pkg), + alpm_dep_compute_string(e->optdep)); + } break; case ALPM_EVENT_DATABASE_MISSING: if(!config->op_s_sync) { pm_printf(ALPM_LOG_WARNING, - "database file for '%s' does not exist\n", (char *)data1); + "database file for '%s' does not exist\n", + ((alpm_event_database_missing_t *) event)->dbname); } break; /* all the simple done events, with fallthrough for each */ - case ALPM_EVENT_REINSTALL_DONE: - case ALPM_EVENT_REMOVE_DONE: case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: case ALPM_EVENT_RESOLVEDEPS_DONE: diff --git a/src/pacman/callback.h b/src/pacman/callback.h index 61a7e4c..cdc8ee7 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -25,7 +25,7 @@ #include <alpm.h> /* callback to handle messages/notifications from libalpm */ -void cb_event(alpm_event_t event, void *data1, void *data2); +void cb_event(alpm_event_t *event); /* callback to handle questions from libalpm (yes/no) */ void cb_question(alpm_question_t event, void *data1, void *data2, -- 1.8.5.2
On 11/01/14 01:25, Olivier Brunel wrote:
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered.
With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 31 ++++++----- lib/libalpm/alpm.h | 148 +++++++++++++++++++++++++++++--------------------- lib/libalpm/be_sync.c | 6 +- lib/libalpm/handle.h | 4 +- lib/libalpm/remove.c | 25 +++++++-- lib/libalpm/sync.c | 81 +++++++++++++++++++-------- lib/libalpm/util.c | 6 +- src/pacman/callback.c | 87 ++++++++++++++++------------- src/pacman/callback.h | 2 +- 9 files changed, 241 insertions(+), 149 deletions(-)
I'd like someone else to comment on this before I pull it given the size of the patch. It looks good to me. Allan
I'm not the biggest fan how the casting is working here. We have various different structures we can send through now but they all need to be cast down and then manually cast back up. I think I'd rather have the base structure done as union then. But if we're going this far, why now consider going a little farther with this. The transaction events are handled in a loop but don't seem to require anything from the context of the loop. So there is no reason that they can't be reimplemented as callbacks. And instead of having one callback function which does everything, we can introduce one for each of kind of event. The transaction can be seeded with a structure pointing to all the various callbacks. Then we start treating a transaction like an event loop. This would improve type safety since we don't have to cast anything anymore. This would improve readability since we don't have to rely on casts and heavy switch statements. Just an idea. Back on topic, I do like this change.
On 16/01/14 02:02, Simon Gomizelj wrote:
I'm not the biggest fan how the casting is working here. We have various different structures we can send through now but they all need to be cast down and then manually cast back up. I think I'd rather have the base structure done as union then.
But if we're going this far, why now consider going a little farther with this.
The transaction events are handled in a loop but don't seem to require anything from the context of the loop. So there is no reason that they can't be reimplemented as callbacks.
I'm missing what you mean by this? What loop?
And instead of having one callback function which does everything, we can introduce one for each of kind of event. The transaction can be seeded with a structure pointing to all the various callbacks. Then we start treating a transaction like an event loop.
This would improve type safety since we don't have to cast anything anymore. This would improve readability since we don't have to rely on casts and heavy switch statements.
The disadvantage of requiring a callback for each event type is that it requires a callback for each event type... At the moment, a new frontend can just start providing a dummy event callback function and gradually deal with the callbacks rather than having to provide many functions immediately.
Just an idea. Back on topic, I do like this change.
When ALPM emits a log message, it still goes through _alpm_log() but instead of calling a specific log callback, it goes as an event. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 37 +++++++++++++++++++++---------------- lib/libalpm/handle.c | 13 ------------- lib/libalpm/handle.h | 1 - lib/libalpm/log.c | 14 +++++++++----- src/pacman/callback.c | 36 ++++++++++++++++++------------------ src/pacman/callback.h | 4 ---- src/pacman/conf.c | 1 - src/util/cleanupdelta.c | 14 ++++++++------ src/util/testdb.c | 14 ++++++++------ src/util/testpkg.c | 14 ++++++++------ 10 files changed, 72 insertions(+), 76 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 9379372..2234a77 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -261,16 +261,6 @@ typedef struct _alpm_siglist_t { * Logging facilities */ -/** Logging Levels */ -typedef enum _alpm_loglevel_t { - ALPM_LOG_ERROR = 1, - ALPM_LOG_WARNING = (1 << 1), - ALPM_LOG_DEBUG = (1 << 2), - ALPM_LOG_FUNCTION = (1 << 3) -} alpm_loglevel_t; - -typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list); - int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4))); @@ -345,7 +335,9 @@ typedef enum _alpm_event_type_t { /** Downloading missing keys into keyring. */ ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ - ALPM_EVENT_KEY_DOWNLOAD_DONE + ALPM_EVENT_KEY_DOWNLOAD_DONE, + /** A log message was emitted; See alpm_event_log_t for arguments. */ + ALPM_EVENT_LOG } alpm_event_type_t; /** Events. @@ -412,6 +404,24 @@ typedef struct _alpm_event_database_missing_t { const char *dbname; } alpm_event_database_missing_t; +/** Log levels. */ +typedef enum _alpm_loglevel_t { + ALPM_LOG_ERROR = 1, + ALPM_LOG_WARNING = (1 << 1), + ALPM_LOG_DEBUG = (1 << 2), + ALPM_LOG_FUNCTION = (1 << 3) +} alpm_loglevel_t; + +typedef struct _alpm_event_log_t { + /** Type of event. */ + alpm_event_type_t type; + /** Log level. */ + alpm_loglevel_t level; + /** Message. */ + const char *fmt; + va_list args; +} alpm_event_log_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); @@ -487,11 +497,6 @@ char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url); * @{ */ -/** Returns the callback used for logging. */ -alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle); -/** Sets the callback used for logging. */ -int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb); - /** Returns the callback used to report download progress. */ alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle); /** Sets the callback used to report download progress. */ diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 44457e6..1f35a79 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -132,12 +132,6 @@ int _alpm_handle_unlock(alpm_handle_t *handle) } -alpm_cb_log SYMEXPORT alpm_option_get_logcb(alpm_handle_t *handle) -{ - CHECK_HANDLE(handle, return NULL); - return handle->logcb; -} - alpm_cb_download SYMEXPORT alpm_option_get_dlcb(alpm_handle_t *handle) { CHECK_HANDLE(handle, return NULL); @@ -258,13 +252,6 @@ int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle) return handle->checkspace; } -int SYMEXPORT alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb) -{ - CHECK_HANDLE(handle, return -1); - handle->logcb = cb; - return 0; -} - int SYMEXPORT alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb) { CHECK_HANDLE(handle, return -1); diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index d767fb6..2acbfc8 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -63,7 +63,6 @@ struct __alpm_handle_t { #endif /* callback functions */ - alpm_cb_log logcb; /* Log callback function */ alpm_cb_download dlcb; /* Download callback function */ alpm_cb_totaldl totaldlcb; /* Total download callback function */ alpm_cb_fetch fetchcb; /* Download file callback function */ diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index c4a9d84..b8fdea8 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -81,15 +81,19 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix, void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...) { - va_list args; + alpm_event_log_t event = { + .type = ALPM_EVENT_LOG, + .level = flag, + .fmt = fmt + }; - if(handle == NULL || handle->logcb == NULL) { + if(handle == NULL || handle->eventcb == NULL) { return; } - va_start(args, fmt); - handle->logcb(flag, fmt, args); - va_end(args); + va_start(event.args, fmt); + EVENT(handle, &event); + va_end(event.args); } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 8b67ffc..5a6961d 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -270,6 +270,24 @@ void cb_event(alpm_event_t *event) ((alpm_event_database_missing_t *) event)->dbname); } break; + case ALPM_EVENT_LOG: + { + alpm_event_log_t *e = (alpm_event_log_t *) event; + if(!e->fmt || strlen(e->fmt) == 0) { + break; + } + + if(on_progress) { + char *string = NULL; + pm_vasprintf(&string, e->level, e->fmt, e->args); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_vfprintf(stderr, e->level, e->fmt, e->args); + } + } + break; /* all the simple done events, with fallthrough for each */ case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: @@ -777,22 +795,4 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) return; } -/* Callback to handle notifications from the library */ -void cb_log(alpm_loglevel_t level, const char *fmt, va_list args) -{ - if(!fmt || strlen(fmt) == 0) { - return; - } - - if(on_progress) { - char *string = NULL; - pm_vasprintf(&string, level, fmt, args); - if(string != NULL) { - output = alpm_list_add(output, string); - } - } else { - pm_vfprintf(stderr, level, fmt, args); - } -} - /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/callback.h b/src/pacman/callback.h index cdc8ee7..31abb4e 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -40,10 +40,6 @@ void cb_dl_total(off_t total); /* callback to handle display of download progress */ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total); -/* callback to handle messages/notifications from pacman library */ -__attribute__((format(printf, 2, 0))) -void cb_log(alpm_loglevel_t level, const char *fmt, va_list args); - #endif /* _PM_CALLBACK_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 5450f3b..051481a 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -675,7 +675,6 @@ static int setup_libalpm(void) } config->handle = handle; - alpm_option_set_logcb(handle, cb_log); alpm_option_set_dlcb(handle, cb_dl_progress); alpm_option_set_eventcb(handle, cb_event); alpm_option_set_questioncb(handle, cb_question); diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index b57b203..558e03d 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -35,17 +35,19 @@ static void cleanup(int signum) exit(signum); } -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) +static void output_cb(alpm_event_log_t *event) { - if(strlen(fmt)) { - switch(level) { + if(event->type != ALPM_EVENT_LOG) { + return; + } + if(strlen(event->fmt)) { + switch(event->level) { case ALPM_LOG_ERROR: printf("error: "); break; case ALPM_LOG_WARNING: printf("warning: "); break; /* case ALPM_LOG_DEBUG: printf("debug: "); break; */ default: return; } - vprintf(fmt, args); + vprintf(event->fmt, event->args); } } @@ -126,7 +128,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); + alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb); checkdbs(dbnames); alpm_list_free(dbnames); diff --git a/src/util/testdb.c b/src/util/testdb.c index 53cdb3c..8940e3b 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -39,16 +39,18 @@ static void cleanup(int signum) exit(signum); } -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) +static void output_cb(alpm_event_log_t *event) { - if(strlen(fmt)) { - switch(level) { + if(event->type != ALPM_EVENT_LOG) { + return; + } + if(strlen(event->fmt)) { + switch(event->level) { case ALPM_LOG_ERROR: printf("error: "); break; case ALPM_LOG_WARNING: printf("warning: "); break; default: return; } - vprintf(fmt, args); + vprintf(event->fmt, event->args); } } @@ -282,7 +284,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); + alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb); if(!dbnames) { errors = check_localdb(); diff --git a/src/util/testpkg.c b/src/util/testpkg.c index cc7d9c2..39807fe 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -23,18 +23,20 @@ #include <alpm.h> -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) +static void output_cb(alpm_event_log_t *event) { - if(fmt[0] == '\0') { + if(event->type != ALPM_EVENT_LOG) { return; } - switch(level) { + if(event->fmt[0] == '\0') { + return; + } + switch(event->level) { case ALPM_LOG_ERROR: printf("error: "); break; case ALPM_LOG_WARNING: printf("warning: "); break; default: return; /* skip other messages */ } - vprintf(fmt, args); + vprintf(event->fmt, event->args); } int main(int argc, char *argv[]) @@ -59,7 +61,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); + alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb); /* set gpgdir to default */ alpm_option_set_gpgdir(handle, GPGDIR); -- 1.8.5.2
To go along with RETRIEVE_START, one other event will be emmitted once the downloads are done: RETRIEVE_DONE if all files were successfully downloaded, else RETRIEVE_FAILED. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 4 ++++ lib/libalpm/sync.c | 3 +++ src/pacman/callback.c | 2 ++ 3 files changed, 9 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 2234a77..2073c57 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -318,6 +318,10 @@ typedef enum _alpm_event_type_t { ALPM_EVENT_SCRIPTLET_INFO, /** Files will be downloaded from a repository. */ ALPM_EVENT_RETRIEVE_START, + /** Files were downloaded from a repository. */ + ALPM_EVENT_RETRIEVE_DONE, + /** Not all files were successfully downloaded from a repository. */ + ALPM_EVENT_RETRIEVE_FAILED, /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, /** Disk space usage was computed for a package. */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 63adba4..7fd1312 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -972,12 +972,15 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas) event.type = ALPM_EVENT_RETRIEVE_START; EVENT(handle, &event); + event.type = ALPM_EVENT_RETRIEVE_DONE; for(i = files; i; i = i->next) { if(download_single_file(handle, i->data, cachedir) == -1) { errors++; + event.type = ALPM_EVENT_RETRIEVE_FAILED; _alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n")); } } + EVENT(handle, &event); } finish: diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 5a6961d..357ded7 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -300,6 +300,8 @@ void cb_event(alpm_event_t *event) case ALPM_EVENT_DELTA_INTEGRITY_DONE: case ALPM_EVENT_DELTA_PATCHES_DONE: case ALPM_EVENT_DISKSPACE_DONE: + case ALPM_EVENT_RETRIEVE_DONE: + case ALPM_EVENT_RETRIEVE_FAILED: /* nothing */ break; } -- 1.8.5.2
These will be emmitted when download a package file from a repository, indicating that the download starts, and whether it was successfull or not. Note that when multiple servers are available, no event is emmitted when switching to another server. (This doesn't apply to alpm_fetch_pkgurl(), but since it is called by the frontend, it shouldn't have problems knowing when the download starts and when it ends.) Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/alpm.h | 16 ++++++++++++++++ lib/libalpm/sync.c | 9 +++++++++ src/pacman/callback.c | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 2073c57..40d8e7b 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -322,6 +322,15 @@ typedef enum _alpm_event_type_t { ALPM_EVENT_RETRIEVE_DONE, /** Not all files were successfully downloaded from a repository. */ ALPM_EVENT_RETRIEVE_FAILED, + /** A file will be downloaded from a repository; See alpm_event_pkgdownload_t + * for arguments */ + ALPM_EVENT_PKGDOWNLOAD_START, + /** A file was downloaded from a repository; See alpm_event_pkgdownload_t + * for arguments */ + ALPM_EVENT_PKGDOWNLOAD_DONE, + /** A file failed to be downloaded from a repository; See + * alpm_event_pkgdownload_t for arguments */ + ALPM_EVENT_PKGDOWNLOAD_FAILED, /** Disk space usage will be computed for a package. */ ALPM_EVENT_DISKSPACE_START, /** Disk space usage was computed for a package. */ @@ -426,6 +435,13 @@ typedef struct _alpm_event_log_t { va_list args; } alpm_event_log_t; +typedef struct _alpm_event_pkgdownload_t { + /** Type of event. */ + alpm_event_type_t type; + /** Name of the file */ + const char *file; +} alpm_event_pkgdownload_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 7fd1312..06d8d15 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -892,11 +892,16 @@ static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t static int download_single_file(alpm_handle_t *handle, struct dload_payload *payload, const char *cachedir) { + alpm_event_pkgdownload_t event = { + .type = ALPM_EVENT_PKGDOWNLOAD_START, + .file = payload->remote_name + }; const alpm_list_t *server; payload->handle = handle; payload->allow_resume = 1; + EVENT(handle, &event); for(server = payload->servers; server; server = server->next) { const char *server_url = server->data; size_t len; @@ -907,6 +912,8 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name); if(_alpm_download(payload, cachedir, NULL, NULL) != -1) { + event.type = ALPM_EVENT_PKGDOWNLOAD_DONE; + EVENT(handle, &event); return 0; } @@ -914,6 +921,8 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay payload->unlink_on_fail = 0; } + event.type = ALPM_EVENT_PKGDOWNLOAD_FAILED; + EVENT(handle, &event); return -1; } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 357ded7..b38b77b 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -302,6 +302,10 @@ void cb_event(alpm_event_t *event) case ALPM_EVENT_DISKSPACE_DONE: case ALPM_EVENT_RETRIEVE_DONE: case ALPM_EVENT_RETRIEVE_FAILED: + /* we can safely ignore those as well */ + case ALPM_EVENT_PKGDOWNLOAD_START: + case ALPM_EVENT_PKGDOWNLOAD_DONE: + case ALPM_EVENT_PKGDOWNLOAD_FAILED: /* nothing */ break; } -- 1.8.5.2
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 41 +++++++++++++++++++++++++++++++++++------ lib/libalpm/alpm.h | 41 ++++++++++++++++++++++++++++++++++++++++- lib/libalpm/remove.c | 7 ++++++- src/pacman/callback.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/util.c | 13 +++++++++++++ src/pacman/util.h | 1 + 6 files changed, 143 insertions(+), 8 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 1eaea36..649d6a9 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -363,8 +363,14 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, newpath)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"), - filename, newpath); + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 0, + .oldpkg = oldpkg, + .newpkg = newpkg, + .oldfile = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s installed as %s\n", filename, newpath); } @@ -391,8 +397,12 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, filename)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, - _("%s saved as %s\n"), filename, newpath); + alpm_event_pacorig_created_t event = { + .type = ALPM_EVENT_PACORIG_CREATED, + .newpkg = newpkg, + .oldfile = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", filename, newpath); } @@ -407,14 +417,16 @@ needbackup_cleanup: free(hash_local); free(hash_pkg); } else { + size_t len; /* we didn't need a backup */ if(notouch) { /* change the path to a .pacnew extension */ _alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename); - _alpm_log(handle, ALPM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: extracting %s as %s.pacnew\n", filename, filename); - strncat(filename, ".pacnew", PATH_MAX - strlen(filename)); + /* remember len so we can get the old filename back for the event */ + len = strlen(filename); + strncat(filename, ".pacnew", PATH_MAX - len); } else { _alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename); } @@ -433,6 +445,23 @@ needbackup_cleanup: return errors; } + if(notouch) { + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 1, + .oldpkg = oldpkg, + .newpkg = newpkg, + .oldfile = filename + }; + /* "remove" the .pacnew suffix */ + if(len < PATH_MAX) + filename[len] = '\0'; + EVENT(handle, &event); + /* restore */ + if(len < PATH_MAX) + filename[len] = '.'; + } + /* calculate an hash if this is in newpkg's backup */ alpm_list_t *i; for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) { diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 40d8e7b..626d875 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -350,7 +350,15 @@ typedef enum _alpm_event_type_t { /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE, /** A log message was emitted; See alpm_event_log_t for arguments. */ - ALPM_EVENT_LOG + ALPM_EVENT_LOG, + /** A .pacnew file was created; See alpm_event_pacnew_created_t for arguments. */ + ALPM_EVENT_PACNEW_CREATED, + /** A .pacsave file was created; See alpm_event_pacsave_created_t for + * arguments */ + ALPM_EVENT_PACSAVE_CREATED, + /** A .pacorig file was created; See alpm_event_pacorig_created_t for + * arguments */ + ALPM_EVENT_PACORIG_CREATED } alpm_event_type_t; /** Events. @@ -442,6 +450,37 @@ typedef struct _alpm_event_pkgdownload_t { const char *file; } alpm_event_pkgdownload_t; +typedef struct _alpm_event_pacnew_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Whether the creation was result of a NoUpgrade or not */ + int from_noupgrade; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New Package. */ + alpm_pkg_t *newpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacnew_created_t; + +typedef struct _alpm_event_pacsave_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacsave_created_t; + +typedef struct _alpm_event_pacorig_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** New package. */ + alpm_pkg_t *newpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacorig_created_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index c2831e4..1b83dfd 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -519,6 +519,11 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, int cmp = filehash ? strcmp(filehash, backup->hash) : 0; FREE(filehash); if(cmp != 0) { + alpm_event_pacsave_created_t event = { + .type = ALPM_EVENT_PACSAVE_CREATED, + .oldpkg = oldpkg, + .oldfile = file + }; char *newpath; size_t len = strlen(file) + 8 + 1; MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); @@ -533,7 +538,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, free(newpath); return -1; } - _alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", file, newpath); free(newpath); diff --git a/src/pacman/callback.c b/src/pacman/callback.c index b38b77b..eeeaafe 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -288,6 +288,54 @@ void cb_event(alpm_event_t *event) } } break; + case ALPM_EVENT_PACNEW_CREATED: + { + alpm_event_pacnew_created_t *e = (alpm_event_pacnew_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"), + e->oldfile, e->oldfile); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"), + e->oldfile, e->oldfile); + } + } + break; + case ALPM_EVENT_PACSAVE_CREATED: + { + alpm_event_pacsave_created_t *e = (alpm_event_pacsave_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"), + e->oldfile, e->oldfile); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"), + e->oldfile, e->oldfile); + } + } + break; + case ALPM_EVENT_PACORIG_CREATED: + { + alpm_event_pacorig_created_t *e = (alpm_event_pacorig_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"), + e->oldfile, e->oldfile); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"), + e->oldfile, e->oldfile); + } + } + break; /* all the simple done events, with fallthrough for each */ case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: diff --git a/src/pacman/util.c b/src/pacman/util.c index 58b0cec..b86a3b8 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1577,6 +1577,19 @@ int pm_asprintf(char **string, const char *format, ...) return ret; } +int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) +{ + int ret = 0; + va_list args; + + /* print the message using va_arg list */ + va_start(args, format); + ret = pm_vasprintf(string, level, format, args); + va_end(args); + + return ret; +} + int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) { int ret = 0; diff --git a/src/pacman/util.h b/src/pacman/util.h index 747a67e..ec2c86e 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -78,6 +78,7 @@ int noyes(const char *format, ...) __attribute__((format(printf, 1, 2))); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3))); int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); +int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); #endif /* _PM_UTIL_H */ -- 1.8.5.2
On 11/01/14 01:25, Olivier Brunel wrote:
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user.
Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 41 +++++++++++++++++++++++++++++++++++------ lib/libalpm/alpm.h | 41 ++++++++++++++++++++++++++++++++++++++++- lib/libalpm/remove.c | 7 ++++++- src/pacman/callback.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/util.c | 13 +++++++++++++ src/pacman/util.h | 1 + 6 files changed, 143 insertions(+), 8 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 1eaea36..649d6a9 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -363,8 +363,14 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, newpath)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"), - filename, newpath); + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 0, + .oldpkg = oldpkg, + .newpkg = newpkg, + .oldfile = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s installed as %s\n", filename, newpath); } @@ -391,8 +397,12 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, filename)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, - _("%s saved as %s\n"), filename, newpath); + alpm_event_pacorig_created_t event = { + .type = ALPM_EVENT_PACORIG_CREATED, + .newpkg = newpkg, + .oldfile = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", filename, newpath); } @@ -407,14 +417,16 @@ needbackup_cleanup: free(hash_local); free(hash_pkg); } else { + size_t len; /* we didn't need a backup */ if(notouch) { /* change the path to a .pacnew extension */ _alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename); - _alpm_log(handle, ALPM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: extracting %s as %s.pacnew\n", filename, filename);
For all other actions, the alpm_logaction() call is done right after the event and has the the exact same warning printed by pacman. Move this down to the next if(notouch) block and adjust the message to past tense.
- strncat(filename, ".pacnew", PATH_MAX - strlen(filename)); + /* remember len so we can get the old filename back for the event */ + len = strlen(filename); + strncat(filename, ".pacnew", PATH_MAX - len); } else { _alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename); } @@ -433,6 +445,23 @@ needbackup_cleanup: return errors; }
+ if(notouch) { + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 1, + .oldpkg = oldpkg, + .newpkg = newpkg, + .oldfile = filename + }; + /* "remove" the .pacnew suffix */ + if(len < PATH_MAX)
I don't think these checks are necessary. If the filename exceeded PATH_MAX in length, we would need to detect this much earlier in the process. So no need to check here.
+ filename[len] = '\0'; + EVENT(handle, &event); + /* restore */ + if(len < PATH_MAX) + filename[len] = '.'; + } + /* calculate an hash if this is in newpkg's backup */ alpm_list_t *i; for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) { diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 40d8e7b..626d875 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -350,7 +350,15 @@ typedef enum _alpm_event_type_t { /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE, /** A log message was emitted; See alpm_event_log_t for arguments. */ - ALPM_EVENT_LOG + ALPM_EVENT_LOG, + /** A .pacnew file was created; See alpm_event_pacnew_created_t for arguments. */ + ALPM_EVENT_PACNEW_CREATED, + /** A .pacsave file was created; See alpm_event_pacsave_created_t for + * arguments */ + ALPM_EVENT_PACSAVE_CREATED, + /** A .pacorig file was created; See alpm_event_pacorig_created_t for + * arguments */ + ALPM_EVENT_PACORIG_CREATED } alpm_event_type_t;
/** Events. @@ -442,6 +450,37 @@ typedef struct _alpm_event_pkgdownload_t { const char *file; } alpm_event_pkgdownload_t;
+typedef struct _alpm_event_pacnew_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Whether the creation was result of a NoUpgrade or not */ + int from_noupgrade; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New Package. */ + alpm_pkg_t *newpkg; + /** Filename of the old file. */ + const char *oldfile;
Bit if a bikeshed here... but I'd like this just referred to as "file" being the file name of the altered file without suffix. Having it called oldfile makes me think it is associated with oldpkg, when it is really being installed from newpkg. Do the same in the other two for consistency. Mention the lack of suffix in the comment.
+} alpm_event_pacnew_created_t; + +typedef struct _alpm_event_pacsave_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacsave_created_t; + +typedef struct _alpm_event_pacorig_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** New package. */ + alpm_pkg_t *newpkg; + /** Filename of the old file. */ + const char *oldfile; +} alpm_event_pacorig_created_t; +
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user. Note that there are 2 cases for installing a .pacnew file, to not overwrite user changes and because file is in NoUpgrade. In the later case the warning was a bit different: it happened before and said "extracting" instead of "installed." Now both happen after and are phrased the same. Signed-off-by: Olivier Brunel <jjk@jjacky.com> --- lib/libalpm/add.c | 43 +++++++++++++++++++++++++++++++++++-------- lib/libalpm/alpm.h | 41 ++++++++++++++++++++++++++++++++++++++++- lib/libalpm/remove.c | 7 ++++++- src/pacman/callback.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/util.c | 13 +++++++++++++ src/pacman/util.h | 1 + 6 files changed, 143 insertions(+), 10 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 9bd0fd2..d626ef9 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -363,8 +363,14 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, newpath)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"), - filename, newpath); + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 0, + .oldpkg = oldpkg, + .newpkg = newpkg, + .file = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s installed as %s\n", filename, newpath); } @@ -391,8 +397,12 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, if(try_rename(handle, checkfile, filename)) { errors++; } else { - _alpm_log(handle, ALPM_LOG_WARNING, - _("%s saved as %s\n"), filename, newpath); + alpm_event_pacorig_created_t event = { + .type = ALPM_EVENT_PACORIG_CREATED, + .newpkg = newpkg, + .file = filename + }; + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", filename, newpath); } @@ -407,14 +417,14 @@ needbackup_cleanup: free(hash_local); free(hash_pkg); } else { + size_t len; /* we didn't need a backup */ if(notouch) { /* change the path to a .pacnew extension */ _alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename); - _alpm_log(handle, ALPM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename); - alpm_logaction(handle, ALPM_CALLER_PREFIX, - "warning: extracting %s as %s.pacnew\n", filename, filename); - strncat(filename, ".pacnew", PATH_MAX - strlen(filename)); + /* remember len so we can get the old filename back for the event */ + len = strlen(filename); + strncat(filename, ".pacnew", PATH_MAX - len); } else { _alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename); } @@ -433,6 +443,23 @@ needbackup_cleanup: return errors; } + if(notouch) { + alpm_event_pacnew_created_t event = { + .type = ALPM_EVENT_PACNEW_CREATED, + .from_noupgrade = 1, + .oldpkg = oldpkg, + .newpkg = newpkg, + .file = filename + }; + /* "remove" the .pacnew suffix */ + filename[len] = '\0'; + EVENT(handle, &event); + alpm_logaction(handle, ALPM_CALLER_PREFIX, + "warning: %s installed as %s.pacnew\n", filename, filename); + /* restore */ + filename[len] = '.'; + } + /* calculate an hash if this is in newpkg's backup */ alpm_list_t *i; for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) { diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 5fc9c0d..b0adb95 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -350,7 +350,15 @@ typedef enum _alpm_event_type_t { /** Key downloading is finished. */ ALPM_EVENT_KEY_DOWNLOAD_DONE, /** A log message was emitted; See alpm_event_log_t for arguments. */ - ALPM_EVENT_LOG + ALPM_EVENT_LOG, + /** A .pacnew file was created; See alpm_event_pacnew_created_t for arguments. */ + ALPM_EVENT_PACNEW_CREATED, + /** A .pacsave file was created; See alpm_event_pacsave_created_t for + * arguments */ + ALPM_EVENT_PACSAVE_CREATED, + /** A .pacorig file was created; See alpm_event_pacorig_created_t for + * arguments */ + ALPM_EVENT_PACORIG_CREATED } alpm_event_type_t; /** Events. @@ -442,6 +450,37 @@ typedef struct _alpm_event_pkgdownload_t { const char *file; } alpm_event_pkgdownload_t; +typedef struct _alpm_event_pacnew_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Whether the creation was result of a NoUpgrade or not */ + int from_noupgrade; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** New Package. */ + alpm_pkg_t *newpkg; + /** Filename of the file without the .pacnew suffix */ + const char *file; +} alpm_event_pacnew_created_t; + +typedef struct _alpm_event_pacsave_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** Old package. */ + alpm_pkg_t *oldpkg; + /** Filename of the file without the .pacsave suffix. */ + const char *file; +} alpm_event_pacsave_created_t; + +typedef struct _alpm_event_pacorig_created_t { + /** Type of event. */ + alpm_event_type_t type; + /** New package. */ + alpm_pkg_t *newpkg; + /** Filename of the file without the .pacorig suffix. */ + const char *file; +} alpm_event_pacorig_created_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index dce5578..aa11d9f 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -520,6 +520,11 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, int cmp = filehash ? strcmp(filehash, backup->hash) : 0; FREE(filehash); if(cmp != 0) { + alpm_event_pacsave_created_t event = { + .type = ALPM_EVENT_PACSAVE_CREATED, + .oldpkg = oldpkg, + .file = file + }; char *newpath; size_t len = strlen(file) + 8 + 1; MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); @@ -534,7 +539,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, free(newpath); return -1; } - _alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); + EVENT(handle, &event); alpm_logaction(handle, ALPM_CALLER_PREFIX, "warning: %s saved as %s\n", file, newpath); free(newpath); diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 2540b73..340a3a1 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -288,6 +288,54 @@ void cb_event(alpm_event_t *event) } } break; + case ALPM_EVENT_PACNEW_CREATED: + { + alpm_event_pacnew_created_t *e = (alpm_event_pacnew_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"), + e->file, e->file); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"), + e->file, e->file); + } + } + break; + case ALPM_EVENT_PACSAVE_CREATED: + { + alpm_event_pacsave_created_t *e = (alpm_event_pacsave_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"), + e->file, e->file); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"), + e->file, e->file); + } + } + break; + case ALPM_EVENT_PACORIG_CREATED: + { + alpm_event_pacorig_created_t *e = (alpm_event_pacorig_created_t *) event; + if(on_progress) { + char *string = NULL; + pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"), + e->file, e->file); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"), + e->file, e->file); + } + } + break; /* all the simple done events, with fallthrough for each */ case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: diff --git a/src/pacman/util.c b/src/pacman/util.c index 91f8fb3..d42e27b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1579,6 +1579,19 @@ int pm_asprintf(char **string, const char *format, ...) return ret; } +int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) +{ + int ret = 0; + va_list args; + + /* print the message using va_arg list */ + va_start(args, format); + ret = pm_vasprintf(string, level, format, args); + va_end(args); + + return ret; +} + int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) { int ret = 0; diff --git a/src/pacman/util.h b/src/pacman/util.h index 94a6dc8..4a31e89 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -78,6 +78,7 @@ int noyes(const char *format, ...) __attribute__((format(printf, 1, 2))); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3))); int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); +int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); #endif /* _PM_UTIL_H */ -- 1.8.5.4
On 13/02/14 01:32, Olivier Brunel wrote:
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user.
Note that there are 2 cases for installing a .pacnew file, to not overwrite user changes and because file is in NoUpgrade. In the later case the warning was a bit different: it happened before and said "extracting" instead of "installed." Now both happen after and are phrased the same.
Signed-off-by: Olivier Brunel <jjk@jjacky.com> ---
Looks good. Allan
participants (4)
-
Allan McRae
-
Andrew Gregory
-
Olivier Brunel
-
Simon Gomizelj