[pacman-dev] Another attempt at fixing sync printing multiple times with --noprogressbar
Last month, I sent in a patch[1] trying to fix the issue that when pacman is run with --noprogressbar, pacman sometimes prints the message "downloading foo" multiple times. Allan suggested that I fix the underlying issue; looking at a previous thread[2], I gather that the issue is that a callback function called multiple times isn't the correct place to print something just once. [1]: https://lists.archlinux.org/pipermail/pacman-dev/2016-June/021149.html [2]: https://lists.archlinux.org/pipermail/pacman-dev/2015-May/020094.html To try and fix it properly, I've sent the following patches: 1) Add new alpm event type for database refresh events 2) Raise database refresh events for refresh start, success and failure 3) Move printing the informational message from the progress callback function to the event handler The main caveat here is that originally, pacman would print "downloading core.db", but now prints "downloading core". There is no user-visible change in package downloading. I tested the changes in valgrind; there are no leaks. I look forward to your critiques. (-: Cheers, Ivy
From: Ivy Foster <ivy.foster@gmail.com> New events of this type: ALPM_EVENT_DATABASE_REFRESH_{START,DONE,FAILED} Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- lib/libalpm/alpm.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 168d71b..2b3e116 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -465,7 +465,16 @@ typedef enum _alpm_event_type_t { /** A hook is starting */ ALPM_EVENT_HOOK_RUN_START, /** A hook has finished running */ - ALPM_EVENT_HOOK_RUN_DONE + ALPM_EVENT_HOOK_RUN_DONE, + /** A database refresh has begun. See alpm_event_database_refresh_t + * for arguments. */ + ALPM_EVENT_DATABASE_REFRESH_START, + /** A database refresh has finished. See alpm_event_database_refresh_t + * for arguments. */ + ALPM_EVENT_DATABASE_REFRESH_DONE, + /** A database refresh has failed. See alpm_event_database_refresh_t + * for arguments. */ + ALPM_EVENT_DATABASE_REFRESH_FAILED } alpm_event_type_t; typedef struct _alpm_event_any_t { @@ -527,6 +536,15 @@ typedef struct _alpm_event_database_missing_t { const char *dbname; } alpm_event_database_missing_t; +typedef struct _alpm_event_database_refresh_t { + /** Type of event */ + alpm_event_type_t type; + /** Name of the database. */ + const char *dbname; + /** File extention of the database. */ + const char *dbext; +} alpm_event_database_refresh_t; + typedef struct _alpm_event_pkgdownload_t { /** Type of event. */ alpm_event_type_t type; @@ -589,6 +607,7 @@ typedef union _alpm_event_t { alpm_event_delta_patch_t delta_patch; alpm_event_scriptlet_info_t scriptlet_info; alpm_event_database_missing_t database_missing; + alpm_event_database_refresh_t database_refresh; alpm_event_pkgdownload_t pkgdownload; alpm_event_pacnew_created_t pacnew_created; alpm_event_pacsave_created_t pacsave_created; -- 2.9.0
From: Ivy Foster <ivy.foster@gmail.com> Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- lib/libalpm/be_sync.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 32a669d..ad97475 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -182,6 +182,10 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) mode_t oldmask; alpm_handle_t *handle; alpm_siglevel_t level; + alpm_event_database_refresh_t event = { + .type = ALPM_EVENT_DATABASE_REFRESH_START, + .dbname = db->treename, + }; /* Sanity checks */ ASSERT(db != NULL, return -1); @@ -238,6 +242,8 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) payload.force = force; payload.unlink_on_fail = 1; + EVENT(db->handle, &event); + ret = _alpm_download(&payload, syncpath, NULL, &final_db_url); _alpm_dload_payload_reset(&payload); updated = (updated || ret == 0); @@ -319,10 +325,13 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) /* pm_errno was set by the download code */ _alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerror(handle->pm_errno)); + event.type = ALPM_EVENT_DATABASE_REFRESH_FAILED; } else { handle->pm_errno = 0; + event.type = ALPM_EVENT_DATABASE_REFRESH_DONE; } + EVENT(db->handle, &event); _alpm_handle_unlock(handle); free(syncpath); umask(oldmask); -- 2.9.0
From: Ivy Foster <ivy.foster@gmail.com> Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- src/pacman/callback.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index ab3e14f..9c29e6d 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -173,6 +173,8 @@ static int number_length(size_t n) /* callback to handle messages/notifications from libalpm transactions */ void cb_event(alpm_event_t *event) { + const unsigned short cols = getcols(); + if(config->print) { return; } @@ -344,6 +346,22 @@ void cb_event(alpm_event_t *event) } } break; + case ALPM_EVENT_PKGDOWNLOAD_START: + { + if(config->noprogressbar || cols == 0) { + alpm_event_pkgdownload_t *e = &event->pkgdownload; + printf(_("downloading %s...\n"), e->file); + } + } + break; + case ALPM_EVENT_DATABASE_REFRESH_START: + { + if(config->noprogressbar || cols == 0) { + alpm_event_database_refresh_t *e = &event->database_refresh; + printf(_("downloading %s...\n"), e->dbname); + } + } + break; /* all the simple done events, with fallthrough for each */ case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: @@ -362,9 +380,10 @@ void cb_event(alpm_event_t *event) case ALPM_EVENT_HOOK_DONE: case ALPM_EVENT_HOOK_RUN_DONE: /* we can safely ignore those as well */ - case ALPM_EVENT_PKGDOWNLOAD_START: case ALPM_EVENT_PKGDOWNLOAD_DONE: case ALPM_EVENT_PKGDOWNLOAD_FAILED: + case ALPM_EVENT_DATABASE_REFRESH_DONE: + case ALPM_EVENT_DATABASE_REFRESH_FAILED: /* nothing */ break; } @@ -679,10 +698,6 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) const unsigned short cols = getcols(); if(config->noprogressbar || cols == 0 || file_total == -1) { - if(file_xfered == 0) { - printf(_("downloading %s...\n"), filename); - fflush(stdout); - } return; } -- 2.9.0
participants (1)
-
ivy.foster@gmail.com