1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

diskspace: remove all libarchive usage

Now that the filelists capture mode and size information, we can read
the data from there and prevent having to loop through and uncompress
every archive to check required diskspace usage.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-16 14:51:04 -05:00
parent 6a6fc3107f
commit 26195f8da1

View File

@ -39,10 +39,6 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
/* libarchive */
#include <archive.h>
#include <archive_entry.h>
/* libalpm */ /* libalpm */
#include "diskspace.h" #include "diskspace.h"
#include "alpm_list.h" #include "alpm_list.h"
@ -189,39 +185,19 @@ static int calculate_removed_size(alpm_handle_t *handle,
static int calculate_installed_size(alpm_handle_t *handle, static int calculate_installed_size(alpm_handle_t *handle,
const alpm_list_t *mount_points, alpm_pkg_t *pkg) const alpm_list_t *mount_points, alpm_pkg_t *pkg)
{ {
int ret=0; alpm_list_t *i;
struct archive *archive;
struct archive_entry *entry;
if((archive = archive_read_new()) == NULL) { for(i = alpm_pkg_get_files(pkg); i; i = i->next) {
handle->pm_errno = PM_ERR_LIBARCHIVE; const alpm_file_t *file = i->data;
ret = -1;
goto cleanup;
}
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
if(archive_read_open_filename(archive, pkg->origin_data.file,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
handle->pm_errno = PM_ERR_PKG_OPEN;
ret = -1;
goto cleanup;
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
alpm_mountpoint_t *mp; alpm_mountpoint_t *mp;
const char *filename;
mode_t mode;
char path[PATH_MAX]; char path[PATH_MAX];
filename = archive_entry_pathname(entry); const char *filename = file->name;
mode = archive_entry_mode(entry);
/* libarchive reports these as zero size anyways */ /* libarchive reports these as zero size anyways */
/* NOTE: if we do start accounting for directory size, a dir matching a /* NOTE: if we do start accounting for directory size, a dir matching a
* mountpoint needs to be attributed to the parent, not the mountpoint. */ * mountpoint needs to be attributed to the parent, not the mountpoint. */
if(S_ISDIR(mode) || S_ISLNK(mode)) { if(S_ISDIR(file->mode) || S_ISLNK(file->mode)) {
continue; continue;
} }
@ -241,21 +217,11 @@ static int calculate_installed_size(alpm_handle_t *handle,
/* 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; (file->size + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize;
mp->used |= USED_INSTALL; mp->used |= USED_INSTALL;
if(archive_read_data_skip(archive)) {
_alpm_log(handle, PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkg->name, archive_error_string(archive));
handle->pm_errno = PM_ERR_LIBARCHIVE;
break;
}
} }
archive_read_finish(archive); return 0;
cleanup:
return ret;
} }
int _alpm_check_diskspace(alpm_handle_t *handle) int _alpm_check_diskspace(alpm_handle_t *handle)