summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/diskspace.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2010-11-16 08:07:43 +0100
committerDan McGee <dan@archlinux.org>2010-12-13 03:30:11 +0100
commit24684a616ed46c635a2236873c8168b9153b5bc1 (patch)
tree8b8111aeec5b01e144187ae1c0a76297734c2a6d /lib/libalpm/diskspace.c
parente22aa23c8f5adb0fd4b7ccbee480a4906ede0346 (diff)
downloadpacman-24684a616ed46c635a2236873c8168b9153b5bc1.tar.gz
pacman-24684a616ed46c635a2236873c8168b9153b5bc1.tar.xz
Display progress bar for disk space checking
Checking disk space needed for a transaction can take a while so add an informative progress bar. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/diskspace.c')
-rw-r--r--lib/libalpm/diskspace.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index e57b4246..1f1a6201 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -44,6 +44,7 @@
#include "alpm_list.h"
#include "util.h"
#include "log.h"
+#include "trans.h"
#include "handle.h"
static int mount_point_cmp(const alpm_mountpoint_t *mp1, const alpm_mountpoint_t *mp2)
@@ -258,6 +259,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db)
int replaces = 0, abort = 0;
alpm_list_t *targ;
pmpkg_t *pkg;
+ int numtargs = alpm_list_count(trans->add);
+ int current = 0;
mount_points = mount_point_list();
if(mount_points == NULL) {
@@ -267,13 +270,22 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db)
replaces = alpm_list_count(trans->remove);
if(replaces) {
- for(targ = trans->remove; targ; targ = targ->next) {
+ numtargs += replaces;
+ for(targ = trans->remove; targ; targ = targ->next, current++) {
+ double percent = (double)current / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (percent * 100),
+ numtargs, current);
+
pkg = (pmpkg_t*)targ->data;
calculate_removed_size(pkg, mount_points);
}
}
- for(targ = trans->add; targ; targ = targ->next) {
+ for(targ = trans->add; targ; targ = targ->next, current++) {
+ double percent = (double)current / numtargs;
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (percent * 100),
+ numtargs, current);
+
pkg = (pmpkg_t*)targ->data;
if(_alpm_db_get_pkgfromcache(db, pkg->name)) {
calculate_removed_size(pkg, mount_points);
@@ -288,6 +300,9 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db)
}
}
+ PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", 100,
+ numtargs, current);
+
for(i = mount_points; i; i = alpm_list_next(i)) {
alpm_mountpoint_t *data = i->data;
if(data->used == 1) {