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>
This commit is contained in:
Allan McRae 2010-11-16 17:07:43 +10:00 committed by Dan McGee
parent e22aa23c8f
commit 24684a616e
4 changed files with 36 additions and 3 deletions

View File

@ -371,6 +371,10 @@ typedef enum _pmtransevt_t {
* The repository's tree name is passed to the callback. * The repository's tree name is passed to the callback.
*/ */
PM_TRANS_EVT_RETRIEVE_START, PM_TRANS_EVT_RETRIEVE_START,
/** Disk space usage will be computed for a package */
PM_TRANS_EVT_DISKSPACE_START,
/** Disk space usage was computed for a package */
PM_TRANS_EVT_DISKSPACE_DONE,
} pmtransevt_t; } pmtransevt_t;
/*@}*/ /*@}*/
@ -389,7 +393,8 @@ typedef enum _pmtransprog_t {
PM_TRANS_PROGRESS_ADD_START, PM_TRANS_PROGRESS_ADD_START,
PM_TRANS_PROGRESS_UPGRADE_START, PM_TRANS_PROGRESS_UPGRADE_START,
PM_TRANS_PROGRESS_REMOVE_START, PM_TRANS_PROGRESS_REMOVE_START,
PM_TRANS_PROGRESS_CONFLICTS_START PM_TRANS_PROGRESS_CONFLICTS_START,
PM_TRANS_PROGRESS_DISKSPACE_START,
} pmtransprog_t; } pmtransprog_t;
/* Transaction Event callback */ /* Transaction Event callback */

View File

@ -44,6 +44,7 @@
#include "alpm_list.h" #include "alpm_list.h"
#include "util.h" #include "util.h"
#include "log.h" #include "log.h"
#include "trans.h"
#include "handle.h" #include "handle.h"
static int mount_point_cmp(const alpm_mountpoint_t *mp1, const alpm_mountpoint_t *mp2) 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; int replaces = 0, abort = 0;
alpm_list_t *targ; alpm_list_t *targ;
pmpkg_t *pkg; pmpkg_t *pkg;
int numtargs = alpm_list_count(trans->add);
int current = 0;
mount_points = mount_point_list(); mount_points = mount_point_list();
if(mount_points == NULL) { if(mount_points == NULL) {
@ -267,13 +270,22 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db)
replaces = alpm_list_count(trans->remove); replaces = alpm_list_count(trans->remove);
if(replaces) { 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; pkg = (pmpkg_t*)targ->data;
calculate_removed_size(pkg, mount_points); 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; pkg = (pmpkg_t*)targ->data;
if(_alpm_db_get_pkgfromcache(db, pkg->name)) { if(_alpm_db_get_pkgfromcache(db, pkg->name)) {
calculate_removed_size(pkg, mount_points); 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)) { for(i = mount_points; i; i = alpm_list_next(i)) {
alpm_mountpoint_t *data = i->data; alpm_mountpoint_t *data = i->data;
if(data->used == 1) { if(data->used == 1) {

View File

@ -999,11 +999,15 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
/* check available disk space */ /* check available disk space */
if(handle->checkspace) { if(handle->checkspace) {
EVENT(trans, PM_TRANS_EVT_DISKSPACE_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "checking available disk space\n"); _alpm_log(PM_LOG_DEBUG, "checking available disk space\n");
if(_alpm_check_diskspace(trans, handle->db_local) == -1) { if(_alpm_check_diskspace(trans, handle->db_local) == -1) {
_alpm_log(PM_LOG_ERROR, _("not enough free disk space\n")); _alpm_log(PM_LOG_ERROR, _("not enough free disk space\n"));
goto error; goto error;
} }
EVENT(trans, PM_TRANS_EVT_DISKSPACE_DONE, NULL, NULL);
} }
/* remove conflicting and to-be-replaced packages */ /* remove conflicting and to-be-replaced packages */

View File

@ -228,6 +228,11 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
case PM_TRANS_EVT_RETRIEVE_START: case PM_TRANS_EVT_RETRIEVE_START:
printf(_(":: Retrieving packages from %s...\n"), (char*)data1); printf(_(":: Retrieving packages from %s...\n"), (char*)data1);
break; break;
case PM_TRANS_EVT_DISKSPACE_START:
if(config->noprogressbar) {
printf(_("checking available disk space...\n"));
}
break;
/* all the simple done events, with fallthrough for each */ /* all the simple done events, with fallthrough for each */
case PM_TRANS_EVT_FILECONFLICTS_DONE: case PM_TRANS_EVT_FILECONFLICTS_DONE:
case PM_TRANS_EVT_CHECKDEPS_DONE: case PM_TRANS_EVT_CHECKDEPS_DONE:
@ -236,6 +241,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
case PM_TRANS_EVT_INTEGRITY_DONE: case PM_TRANS_EVT_INTEGRITY_DONE:
case PM_TRANS_EVT_DELTA_INTEGRITY_DONE: case PM_TRANS_EVT_DELTA_INTEGRITY_DONE:
case PM_TRANS_EVT_DELTA_PATCHES_DONE: case PM_TRANS_EVT_DELTA_PATCHES_DONE:
case PM_TRANS_EVT_DISKSPACE_DONE:
/* nothing */ /* nothing */
break; break;
} }
@ -375,6 +381,9 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
case PM_TRANS_PROGRESS_CONFLICTS_START: case PM_TRANS_PROGRESS_CONFLICTS_START:
opr = _("checking for file conflicts"); opr = _("checking for file conflicts");
break; break;
case PM_TRANS_PROGRESS_DISKSPACE_START:
opr = _("checking available disk space");
break;
default: default:
return; return;
} }