Remove global handle from diskspace.c

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-03 12:36:13 -05:00
parent 7fc635fee0
commit 4015b23e8e
3 changed files with 12 additions and 14 deletions

View file

@ -51,9 +51,6 @@
#include "trans.h" #include "trans.h"
#include "handle.h" #include "handle.h"
/* global handle variable */
extern pmhandle_t *handle;
static int mount_point_cmp(const void *p1, const void *p2) static int mount_point_cmp(const void *p1, const void *p2)
{ {
const alpm_mountpoint_t *mp1 = p1; const alpm_mountpoint_t *mp1 = p1;
@ -151,8 +148,8 @@ static alpm_mountpoint_t *match_mount_point(const alpm_list_t *mount_points,
return NULL; return NULL;
} }
static int calculate_removed_size(const alpm_list_t *mount_points, static int calculate_removed_size(pmhandle_t *handle,
pmpkg_t *pkg) const alpm_list_t *mount_points, pmpkg_t *pkg)
{ {
alpm_list_t *file; alpm_list_t *file;
@ -188,8 +185,8 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
return 0; return 0;
} }
static int calculate_installed_size(const alpm_list_t *mount_points, static int calculate_installed_size(pmhandle_t *handle,
pmpkg_t *pkg) const alpm_list_t *mount_points, pmpkg_t *pkg)
{ {
int ret=0; int ret=0;
struct archive *archive; struct archive *archive;
@ -260,13 +257,14 @@ cleanup:
return ret; return ret;
} }
int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local) int _alpm_check_diskspace(pmhandle_t *handle)
{ {
alpm_list_t *mount_points, *i; alpm_list_t *mount_points, *i;
alpm_mountpoint_t *root_mp; alpm_mountpoint_t *root_mp;
size_t replaces = 0, current = 0, numtargs; size_t replaces = 0, current = 0, numtargs;
int abort = 0; int abort = 0;
alpm_list_t *targ; alpm_list_t *targ;
pmtrans_t *trans = handle->trans;
numtargs = alpm_list_count(trans->add); numtargs = alpm_list_count(trans->add);
mount_points = mount_point_list(); mount_points = mount_point_list();
@ -291,7 +289,7 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
numtargs, current); numtargs, current);
local_pkg = targ->data; local_pkg = targ->data;
calculate_removed_size(mount_points, local_pkg); calculate_removed_size(handle, mount_points, local_pkg);
} }
} }
@ -303,11 +301,11 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
pkg = targ->data; pkg = targ->data;
/* is this package already installed? */ /* is this package already installed? */
local_pkg = _alpm_db_get_pkgfromcache(db_local, pkg->name); local_pkg = _alpm_db_get_pkgfromcache(handle->db_local, pkg->name);
if(local_pkg) { if(local_pkg) {
calculate_removed_size(mount_points, local_pkg); calculate_removed_size(handle, mount_points, local_pkg);
} }
calculate_installed_size(mount_points, pkg); calculate_installed_size(handle, mount_points, pkg);
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;

View file

@ -46,7 +46,7 @@ typedef struct __alpm_mountpoint_t {
FSSTATSTYPE fsp; FSSTATSTYPE fsp;
} alpm_mountpoint_t; } alpm_mountpoint_t;
int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local); int _alpm_check_diskspace(pmhandle_t *handle);
#endif /* _ALPM_DISKSPACE_H */ #endif /* _ALPM_DISKSPACE_H */

View file

@ -935,7 +935,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_DISKSPACE_START, NULL, NULL); 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(handle) == -1) {
_alpm_log(PM_LOG_ERROR, "%s\n", _("not enough free disk space")); _alpm_log(PM_LOG_ERROR, "%s\n", _("not enough free disk space"));
return -1; return -1;
} }