From a27f993600a518ef6a15bd7fb29575b218b58a0a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 19 Sep 2011 21:01:26 -0500 Subject: Split package validation and load loops This adds a some new callback event and progress codes for package loading, which was formerly bundled in with package validation before. The main sync.c loop where loading occurred is now two loops running sequentially. The behavior should not change with this patch outside of progress and event display; more changes will come in following patches. Signed-off-by: Dan McGee --- lib/libalpm/alpm.h | 5 +++++ lib/libalpm/sync.c | 58 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 12 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 202c3cd3..9fe80341 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -305,6 +305,10 @@ typedef enum _alpm_event_t { ALPM_EVENT_INTEGRITY_START, /** Target package's integrity was checked. */ ALPM_EVENT_INTEGRITY_DONE, + /** Target package will be loaded. */ + ALPM_EVENT_LOAD_START, + /** Target package is finished loading. */ + ALPM_EVENT_LOAD_DONE, /** Target deltas's integrity will be checked. */ ALPM_EVENT_DELTA_INTEGRITY_START, /** Target delta's integrity was checked. */ @@ -361,6 +365,7 @@ typedef enum _alpm_progress_t { ALPM_PROGRESS_CONFLICTS_START, ALPM_PROGRESS_DISKSPACE_START, ALPM_PROGRESS_INTEGRITY_START, + ALPM_PROGRESS_LOAD_START, } alpm_progress_t; /** Progress callback */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index a5281078..e1eff032 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -966,11 +966,6 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) alpm_db_t *sdb = alpm_pkg_get_db(spkg); level = alpm_db_get_siglevel(sdb); - /* load the package file and replace pkgcache entry with it in the target list */ - /* TODO: alpm_pkg_get_db() will not work on this target anymore */ - _alpm_log(handle, ALPM_LOG_DEBUG, - "replacing pkgcache entry with package file for target %s\n", - spkg->name); if(_alpm_pkg_validate_internal(handle, filepath, spkg, level) == -1) { prompt_to_delete(handle, filepath, handle->pm_errno); errors++; @@ -978,6 +973,50 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) FREE(filepath); continue; } + FREE(filepath); + } + + PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100, + numtargs, current); + EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL); + + if(errors) { + if(!handle->pm_errno) { + RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); + } + return -1; + } + + if(trans->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) { + return 0; + } + + /* load packages from disk now that they are known-valid */ + numtargs = alpm_list_count(trans->add); + EVENT(handle, ALPM_EVENT_LOAD_START, NULL, NULL); + + current = current_bytes = 0; + errors = 0; + + for(i = trans->add; i; i = i->next, current++) { + alpm_pkg_t *spkg = i->data; + char *filepath; + int percent = (int)(((double)current_bytes / total_bytes) * 100); + + PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", percent, + numtargs, current); + if(spkg->origin == PKG_FROM_FILE) { + continue; /* pkg_load() has been already called, this package is valid */ + } + + current_bytes += spkg->size; + filepath = _alpm_filecache_find(handle, spkg->filename); + + /* load the package file and replace pkgcache entry with it in the target list */ + /* TODO: alpm_pkg_get_db() will not work on this target anymore */ + _alpm_log(handle, ALPM_LOG_DEBUG, + "replacing pkgcache entry with package file for target %s\n", + spkg->name); alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1); if(!pkgfile) { errors++; @@ -991,10 +1030,9 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) _alpm_pkg_free_trans(spkg); /* spkg has been removed from the target list */ } - PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100, + PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100, numtargs, current); - EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL); - + EVENT(handle, ALPM_EVENT_LOAD_DONE, NULL, NULL); if(errors) { if(!handle->pm_errno) { @@ -1003,10 +1041,6 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) return -1; } - if(trans->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) { - return 0; - } - trans->state = STATE_COMMITING; replaces = alpm_list_count(trans->remove); -- cgit v1.2.3-70-g09d2