Convert deltas to dynamic allocation

Another elimination of a static length structure in libalpm. Should result
in a little more memory saved during execution of packages with lots of
deltas attached.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-01-12 01:27:02 -06:00
parent f6785dcb89
commit 927af790ee
4 changed files with 28 additions and 19 deletions

View file

@ -487,7 +487,8 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* DELTAS */
if(inforeq & INFRQ_DELTAS) {
snprintf(path, PATH_MAX, "%s/%s-%s/deltas", db->path, info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/deltas", db->path,
info->name, info->version);
if((fp = fopen(path, "r"))) {
while(!feof(fp)) {
fgets(line, 255, fp);

View file

@ -1,7 +1,7 @@
/*
* delta.c
*
* Copyright (c) 2007 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2007-2008 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -99,7 +99,7 @@ unsigned long _alpm_delta_path_size(alpm_list_t *deltas)
alpm_list_t *dlts = deltas;
while(dlts) {
pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
pmdelta_t *d = alpm_list_getdata(dlts);
sum += d->size;
dlts = alpm_list_next(dlts);
@ -121,7 +121,7 @@ unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas)
alpm_list_t *dlts = deltas;
while(dlts) {
pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
pmdelta_t *d = alpm_list_getdata(dlts);
char *fname = _alpm_filecache_find(d->filename);
if(!fname) {
@ -241,12 +241,12 @@ pmdelta_t *_alpm_delta_parse(char *line)
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
strncpy(delta->from, tmp2, DLT_VERSION_LEN);
STRDUP(delta->from, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
strncpy(delta->to, tmp2, DLT_VERSION_LEN);
STRDUP(delta->to, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
tmp2 = tmp;
tmp = strchr(tmp, ' ');
@ -256,11 +256,20 @@ pmdelta_t *_alpm_delta_parse(char *line)
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
strncpy(delta->filename, tmp2, DLT_FILENAME_LEN);
STRDUP(delta->filename, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
strncpy(delta->md5sum, tmp, DLT_MD5SUM_LEN);
STRDUP(delta->md5sum, tmp, RET_ERR(PM_ERR_MEMORY, NULL));
return(delta);
}
void _alpm_delta_free(pmdelta_t *delta)
{
FREE(delta->from);
FREE(delta->to);
FREE(delta->filename);
FREE(delta->md5sum);
FREE(delta);
}
/* vim: set ts=2 sw=2 noet: */

View file

@ -1,7 +1,7 @@
/*
* delta.h
*
* Copyright (c) 2007 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2007-2008 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,22 +21,20 @@
#include "alpm.h"
#define DLT_FILENAME_LEN 512
#define DLT_VERSION_LEN 64
#define DLT_MD5SUM_LEN 33
struct __pmdelta_t {
char from[DLT_VERSION_LEN];
char to[DLT_VERSION_LEN];
char *from;
char *to;
unsigned long size;
char filename[DLT_FILENAME_LEN];
char md5sum[DLT_MD5SUM_LEN];
char *filename;
char *md5sum;
};
unsigned long _alpm_delta_path_size(alpm_list_t *deltas);
unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas);
pmdelta_t *_alpm_delta_parse(char *line);
alpm_list_t *_alpm_shortest_delta_path(alpm_list_t *deltas, const char *from, const char *to);
void _alpm_delta_free(pmdelta_t *delta);
alpm_list_t *_alpm_shortest_delta_path(alpm_list_t *deltas,
const char *from, const char *to);
#endif /* _ALPM_DELTA_H */

View file

@ -845,7 +845,8 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREELIST(pkg->optdepends);
FREELIST(pkg->conflicts);
FREELIST(pkg->provides);
FREELIST(pkg->deltas);
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
alpm_list_free(pkg->deltas);
if(pkg->origin == PKG_FROM_FILE) {
FREE(pkg->origin_data.file);