diskspace: allow used flag to be toggled for both remove and install

Turn it into an enum rather than a boolean, and use a bitmask like we do for
reading DB entries. The relevant flag is turned on in our two calculate
loops, and anything reading the used flag later can decided which flag (or
either) is relevant.

This will allow the read-only partition code to be triggered on a
remove-only operation, e.g. if /boot was read-only and one tried to remove
grub in a sync transaction. Of course, right now, we don't actually run the
diskspace check code in the '-R' codepath.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-02-11 10:49:30 -06:00
parent 3afe3b6dfb
commit 30f338cce6
2 changed files with 9 additions and 3 deletions

View file

@ -175,6 +175,7 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
/* the addition of (divisor - 1) performs ceil() with integer division */ /* the addition of (divisor - 1) performs ceil() with integer division */
mp->blocks_needed -= mp->blocks_needed -=
(st.st_size + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize; (st.st_size + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize;
mp->used |= USED_REMOVE;
} }
return(0); return(0);
@ -236,7 +237,7 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
/* the addition of (divisor - 1) performs ceil() with integer division */ /* the addition of (divisor - 1) performs ceil() with integer division */
mp->blocks_needed += mp->blocks_needed +=
(archive_entry_size(entry) + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize; (archive_entry_size(entry) + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize;
mp->used = 1; mp->used |= USED_INSTALL;
if(archive_read_data_skip(archive)) { if(archive_read_data_skip(archive)) {
_alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"), _alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
@ -311,7 +312,7 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
_alpm_log(PM_LOG_ERROR, _("Partition %s is mounted read only\n"), _alpm_log(PM_LOG_ERROR, _("Partition %s is mounted read only\n"),
data->mount_dir); data->mount_dir);
abort = 1; abort = 1;
} else if(data->used) { } else if(data->used & USED_INSTALL) {
/* cushion is roughly min(5% capacity, 20MiB) */ /* cushion is roughly min(5% capacity, 20MiB) */
long fivepc = ((long)data->fsp.f_blocks / 20) + 1; long fivepc = ((long)data->fsp.f_blocks / 20) + 1;
long twentymb = (20 * 1024 * 1024 / (long)data->fsp.f_bsize) + 1; long twentymb = (20 * 1024 * 1024 / (long)data->fsp.f_bsize) + 1;

View file

@ -29,6 +29,11 @@
#include "alpm.h" #include "alpm.h"
enum mount_used_level {
USED_REMOVE = 1,
USED_INSTALL = (1 << 1),
};
typedef struct __alpm_mountpoint_t { typedef struct __alpm_mountpoint_t {
/* mount point information */ /* mount point information */
char *mount_dir; char *mount_dir;
@ -36,7 +41,7 @@ typedef struct __alpm_mountpoint_t {
/* storage for additional disk usage calculations */ /* storage for additional disk usage calculations */
long blocks_needed; long blocks_needed;
long max_blocks_needed; long max_blocks_needed;
int used; enum mount_used_level used;
int read_only; int read_only;
FSSTATSTYPE fsp; FSSTATSTYPE fsp;
} alpm_mountpoint_t; } alpm_mountpoint_t;