Clean up handling of size fields
We currently have csize, isize, and size concepts, and sometimes the difference isn't clear. Ensure the following holds: * size (aka csize): always the compressed size of the package; available for everything except local packages (where it will return 0) * isize: always the installed size of the package; available for all three package types Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
c51b9ca0ad
commit
83a1e4fee3
|
@ -653,7 +653,8 @@ const char *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg);
|
||||||
*/
|
*/
|
||||||
const char *alpm_pkg_get_arch(alpm_pkg_t *pkg);
|
const char *alpm_pkg_get_arch(alpm_pkg_t *pkg);
|
||||||
|
|
||||||
/** Returns the size of the package.
|
/** Returns the size of the package. This is only available for sync database
|
||||||
|
* packages and package files, not those loaded from the local database.
|
||||||
* @param pkg a pointer to package
|
* @param pkg a pointer to package
|
||||||
* @return the size of the package in bytes.
|
* @return the size of the package in bytes.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -99,12 +99,6 @@ static const char *_cache_get_arch(alpm_pkg_t *pkg)
|
||||||
return pkg->arch;
|
return pkg->arch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static off_t _cache_get_size(alpm_pkg_t *pkg)
|
|
||||||
{
|
|
||||||
LAZY_LOAD(INFRQ_DESC, -1);
|
|
||||||
return pkg->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static off_t _cache_get_isize(alpm_pkg_t *pkg)
|
static off_t _cache_get_isize(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
LAZY_LOAD(INFRQ_DESC, -1);
|
LAZY_LOAD(INFRQ_DESC, -1);
|
||||||
|
@ -243,7 +237,6 @@ static struct pkg_operations local_pkg_ops = {
|
||||||
.get_installdate = _cache_get_installdate,
|
.get_installdate = _cache_get_installdate,
|
||||||
.get_packager = _cache_get_packager,
|
.get_packager = _cache_get_packager,
|
||||||
.get_arch = _cache_get_arch,
|
.get_arch = _cache_get_arch,
|
||||||
.get_size = _cache_get_size,
|
|
||||||
.get_isize = _cache_get_isize,
|
.get_isize = _cache_get_isize,
|
||||||
.get_reason = _cache_get_reason,
|
.get_reason = _cache_get_reason,
|
||||||
.has_scriptlet = _cache_has_scriptlet,
|
.has_scriptlet = _cache_has_scriptlet,
|
||||||
|
@ -621,15 +614,8 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
||||||
READ_NEXT();
|
READ_NEXT();
|
||||||
info->reason = (alpm_pkgreason_t)atoi(line);
|
info->reason = (alpm_pkgreason_t)atoi(line);
|
||||||
} else if(strcmp(line, "%SIZE%") == 0) {
|
} else if(strcmp(line, "%SIZE%") == 0) {
|
||||||
/* NOTE: the CSIZE and SIZE fields both share the "size" field
|
|
||||||
* in the pkginfo_t struct. This can be done b/c CSIZE
|
|
||||||
* is currently only used in sync databases, and SIZE is
|
|
||||||
* only used in local databases.
|
|
||||||
*/
|
|
||||||
READ_NEXT();
|
READ_NEXT();
|
||||||
info->size = _alpm_strtoofft(line);
|
info->isize = _alpm_strtoofft(line);
|
||||||
/* also store this value to isize */
|
|
||||||
info->isize = info->size;
|
|
||||||
} else if(strcmp(line, "%REPLACES%") == 0) {
|
} else if(strcmp(line, "%REPLACES%") == 0) {
|
||||||
READ_AND_SPLITDEP(info->replaces);
|
READ_AND_SPLITDEP(info->replaces);
|
||||||
} else if(strcmp(line, "%DEPENDS%") == 0) {
|
} else if(strcmp(line, "%DEPENDS%") == 0) {
|
||||||
|
|
|
@ -561,16 +561,8 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
|
||||||
} else if(strcmp(line, "%PACKAGER%") == 0) {
|
} else if(strcmp(line, "%PACKAGER%") == 0) {
|
||||||
READ_AND_STORE(pkg->packager);
|
READ_AND_STORE(pkg->packager);
|
||||||
} else if(strcmp(line, "%CSIZE%") == 0) {
|
} else if(strcmp(line, "%CSIZE%") == 0) {
|
||||||
/* Note: the CSIZE and SIZE fields both share the "size" field in the
|
|
||||||
* pkginfo_t struct. This can be done b/c CSIZE is currently only used
|
|
||||||
* in sync databases, and SIZE is only used in local databases.
|
|
||||||
*/
|
|
||||||
READ_NEXT();
|
READ_NEXT();
|
||||||
pkg->size = _alpm_strtoofft(line);
|
pkg->size = _alpm_strtoofft(line);
|
||||||
/* also store this value to isize if isize is unset */
|
|
||||||
if(pkg->isize == 0) {
|
|
||||||
pkg->isize = pkg->size;
|
|
||||||
}
|
|
||||||
} else if(strcmp(line, "%ISIZE%") == 0) {
|
} else if(strcmp(line, "%ISIZE%") == 0) {
|
||||||
READ_NEXT();
|
READ_NEXT();
|
||||||
pkg->isize = _alpm_strtoofft(line);
|
pkg->isize = _alpm_strtoofft(line);
|
||||||
|
|
|
@ -249,12 +249,11 @@ static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota
|
||||||
|
|
||||||
alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(alpm_pkg_t *pkg)
|
alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
off_t pkgsize = alpm_pkg_get_size(pkg);
|
ASSERT(pkg != NULL, return NULL);
|
||||||
alpm_list_t *unused = find_unused(
|
return find_unused(
|
||||||
alpm_pkg_get_deltas(pkg),
|
alpm_pkg_get_deltas(pkg),
|
||||||
alpm_pkg_get_filename(pkg),
|
alpm_pkg_get_filename(pkg),
|
||||||
pkgsize * MAX_DELTA_RATIO);
|
pkg->size * MAX_DELTA_RATIO);
|
||||||
return unused;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -92,7 +92,6 @@ static time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate
|
||||||
static time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; }
|
static time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; }
|
||||||
static const char *_pkg_get_packager(alpm_pkg_t *pkg) { return pkg->packager; }
|
static const char *_pkg_get_packager(alpm_pkg_t *pkg) { return pkg->packager; }
|
||||||
static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; }
|
static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; }
|
||||||
static off_t _pkg_get_size(alpm_pkg_t *pkg) { return pkg->size; }
|
|
||||||
static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
|
static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
|
||||||
static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; }
|
static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; }
|
||||||
static int _pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg->scriptlet; }
|
static int _pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg->scriptlet; }
|
||||||
|
@ -138,7 +137,6 @@ struct pkg_operations default_pkg_ops = {
|
||||||
.get_installdate = _pkg_get_installdate,
|
.get_installdate = _pkg_get_installdate,
|
||||||
.get_packager = _pkg_get_packager,
|
.get_packager = _pkg_get_packager,
|
||||||
.get_arch = _pkg_get_arch,
|
.get_arch = _pkg_get_arch,
|
||||||
.get_size = _pkg_get_size,
|
|
||||||
.get_isize = _pkg_get_isize,
|
.get_isize = _pkg_get_isize,
|
||||||
.get_reason = _pkg_get_reason,
|
.get_reason = _pkg_get_reason,
|
||||||
.has_scriptlet = _pkg_has_scriptlet,
|
.has_scriptlet = _pkg_has_scriptlet,
|
||||||
|
@ -258,8 +256,7 @@ const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg)
|
||||||
off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg)
|
off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
ASSERT(pkg != NULL, return -1);
|
ASSERT(pkg != NULL, return -1);
|
||||||
pkg->handle->pm_errno = 0;
|
return pkg->size;
|
||||||
return pkg->ops->get_size(pkg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg)
|
off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg)
|
||||||
|
|
|
@ -49,7 +49,6 @@ struct pkg_operations {
|
||||||
time_t (*get_installdate) (alpm_pkg_t *);
|
time_t (*get_installdate) (alpm_pkg_t *);
|
||||||
const char *(*get_packager) (alpm_pkg_t *);
|
const char *(*get_packager) (alpm_pkg_t *);
|
||||||
const char *(*get_arch) (alpm_pkg_t *);
|
const char *(*get_arch) (alpm_pkg_t *);
|
||||||
off_t (*get_size) (alpm_pkg_t *);
|
|
||||||
off_t (*get_isize) (alpm_pkg_t *);
|
off_t (*get_isize) (alpm_pkg_t *);
|
||||||
alpm_pkgreason_t (*get_reason) (alpm_pkg_t *);
|
alpm_pkgreason_t (*get_reason) (alpm_pkg_t *);
|
||||||
int (*has_scriptlet) (alpm_pkg_t *);
|
int (*has_scriptlet) (alpm_pkg_t *);
|
||||||
|
|
|
@ -304,24 +304,23 @@ static int compute_download_size(alpm_pkg_t *newpkg)
|
||||||
size = 0;
|
size = 0;
|
||||||
} else if(handle->usedelta) {
|
} else if(handle->usedelta) {
|
||||||
off_t dltsize;
|
off_t dltsize;
|
||||||
off_t pkgsize = alpm_pkg_get_size(newpkg);
|
|
||||||
|
|
||||||
dltsize = _alpm_shortest_delta_path(handle,
|
dltsize = _alpm_shortest_delta_path(handle,
|
||||||
alpm_pkg_get_deltas(newpkg),
|
alpm_pkg_get_deltas(newpkg),
|
||||||
alpm_pkg_get_filename(newpkg),
|
alpm_pkg_get_filename(newpkg),
|
||||||
&newpkg->delta_path);
|
&newpkg->delta_path);
|
||||||
|
|
||||||
if(newpkg->delta_path && (dltsize < pkgsize * MAX_DELTA_RATIO)) {
|
if(newpkg->delta_path && (dltsize < newpkg->size * MAX_DELTA_RATIO)) {
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n");
|
_alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n");
|
||||||
size = dltsize;
|
size = dltsize;
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "using package size\n");
|
_alpm_log(handle, ALPM_LOG_DEBUG, "using package size\n");
|
||||||
size = alpm_pkg_get_size(newpkg);
|
size = newpkg->size;
|
||||||
alpm_list_free(newpkg->delta_path);
|
alpm_list_free(newpkg->delta_path);
|
||||||
newpkg->delta_path = NULL;
|
newpkg->delta_path = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
size = alpm_pkg_get_size(newpkg);
|
size = newpkg->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
|
_alpm_log(handle, ALPM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
|
||||||
|
@ -833,7 +832,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
|
||||||
ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
||||||
CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
||||||
STRDUP(payload->remote_name, spkg->filename, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
STRDUP(payload->remote_name, spkg->filename, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
||||||
payload->max_size = alpm_pkg_get_size(spkg);
|
payload->max_size = spkg->size;
|
||||||
|
|
||||||
files = alpm_list_add(files, payload);
|
files = alpm_list_add(files, payload);
|
||||||
}
|
}
|
||||||
|
@ -916,7 +915,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
|
||||||
for(i = trans->add; i; i = i->next, current++) {
|
for(i = trans->add; i; i = i->next, current++) {
|
||||||
alpm_pkg_t *spkg = i->data;
|
alpm_pkg_t *spkg = i->data;
|
||||||
if(spkg->origin != PKG_FROM_FILE) {
|
if(spkg->origin != PKG_FROM_FILE) {
|
||||||
total_bytes += alpm_pkg_get_size(spkg);
|
total_bytes += spkg->size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* this can only happen maliciously */
|
/* this can only happen maliciously */
|
||||||
|
@ -942,7 +941,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
|
||||||
continue; /* pkg_load() has been already called, this package is valid */
|
continue; /* pkg_load() has been already called, this package is valid */
|
||||||
}
|
}
|
||||||
|
|
||||||
current_bytes += alpm_pkg_get_size(spkg);
|
current_bytes += spkg->size;
|
||||||
filename = alpm_pkg_get_filename(spkg);
|
filename = alpm_pkg_get_filename(spkg);
|
||||||
filepath = _alpm_filecache_find(handle, filename);
|
filepath = _alpm_filecache_find(handle, filename);
|
||||||
alpm_db_t *sdb = alpm_pkg_get_db(spkg);
|
alpm_db_t *sdb = alpm_pkg_get_db(spkg);
|
||||||
|
|
Loading…
Reference in New Issue