summaryrefslogtreecommitdiff
path: root/lib/libalpm/sync.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-19 21:01:26 -0500
committerDan McGee <dan@archlinux.org>2011-09-20 10:23:11 -0500
commita27f993600a518ef6a15bd7fb29575b218b58a0a (patch)
tree57926bd9d9b37be4961c9c6f86c8fed529d5a5c6 /lib/libalpm/sync.c
parentafdbfc05f771f2c684ee195b46d26b3d08a67085 (diff)
downloadpacman-a27f993600a518ef6a15bd7fb29575b218b58a0a.tar.xz
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 <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/sync.c')
-rw-r--r--lib/libalpm/sync.c58
1 files changed, 46 insertions, 12 deletions
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);