account for partial delta files in download size

Similar to an earlier commit which accounts for .part files for full
packages, calculate the download_size for deltas keeping mind the
possibility of a partial transfer.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-09-07 17:01:00 -04:00 committed by Dan McGee
parent d8eacae7bc
commit 3905ada993

View file

@ -89,12 +89,28 @@ static void graph_init_size(alpm_handle_t *handle, alpm_list_t *vertices)
/* determine whether the delta file already exists */ /* determine whether the delta file already exists */
fpath = _alpm_filecache_find(handle, vdelta->delta); fpath = _alpm_filecache_find(handle, vdelta->delta);
if(fpath) {
md5sum = alpm_compute_md5sum(fpath); md5sum = alpm_compute_md5sum(fpath);
if(fpath && md5sum && strcmp(md5sum, vdelta->delta_md5) == 0) { if(md5sum && strcmp(md5sum, vdelta->delta_md5) == 0) {
vdelta->download_size = 0; vdelta->download_size = 0;
} }
FREE(fpath);
FREE(md5sum); FREE(md5sum);
FREE(fpath);
} else {
char *fnamepart;
CALLOC(fnamepart, strlen(vdelta->delta) + 6, sizeof(char), return);
sprintf(fnamepart, "%s.part", vdelta->delta);
fpath = _alpm_filecache_find(handle, fnamepart);
if(fpath) {
struct stat st;
if(stat(fpath, &st) == 0) {
vdelta->download_size = vdelta->delta_size - st.st_size;
vdelta->download_size = vdelta->download_size < 0 ? 0 : vdelta->download_size;
}
FREE(fpath);
}
FREE(fnamepart);
}
/* determine whether a base 'from' file exists */ /* determine whether a base 'from' file exists */
fpath = _alpm_filecache_find(handle, vdelta->from); fpath = _alpm_filecache_find(handle, vdelta->from);