make compute_download_size consider .part files
Check for the existance of a partial download of a package file before jumping to delta calculations. Currently, if there were 10MiB remaining in a 100MiB the values passed to the front end do not reflect this. Refactored from an old patch originally by Dan. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
befddfc3e6
commit
d8eacae7bc
1 changed files with 24 additions and 3 deletions
|
@ -284,7 +284,8 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
|
||||||
*/
|
*/
|
||||||
static int compute_download_size(alpm_pkg_t *newpkg)
|
static int compute_download_size(alpm_pkg_t *newpkg)
|
||||||
{
|
{
|
||||||
char *fpath;
|
const char *fname;
|
||||||
|
char *fpath, *fnamepart = NULL;
|
||||||
off_t size = 0;
|
off_t size = 0;
|
||||||
alpm_handle_t *handle = newpkg->handle;
|
alpm_handle_t *handle = newpkg->handle;
|
||||||
|
|
||||||
|
@ -295,11 +296,26 @@ static int compute_download_size(alpm_pkg_t *newpkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(newpkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
ASSERT(newpkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
||||||
fpath = _alpm_filecache_find(handle, newpkg->filename);
|
fname = newpkg->filename;
|
||||||
|
fpath = _alpm_filecache_find(handle, fname);
|
||||||
|
|
||||||
|
/* downloaded file exists, so there's nothing to grab */
|
||||||
if(fpath) {
|
if(fpath) {
|
||||||
FREE(fpath);
|
|
||||||
size = 0;
|
size = 0;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
CALLOC(fnamepart, strlen(fname) + 6, sizeof(char), return -1);
|
||||||
|
sprintf(fnamepart, "%s.part", fname);
|
||||||
|
fpath = _alpm_filecache_find(handle, fnamepart);
|
||||||
|
if(fpath) {
|
||||||
|
struct stat st;
|
||||||
|
if(stat(fpath, &st) == 0) {
|
||||||
|
/* subtract the size of the .part file */
|
||||||
|
_alpm_log(handle, ALPM_LOG_DEBUG, "using (package - .part) size\n");
|
||||||
|
size = newpkg->size - st.st_size;
|
||||||
|
size = size < 0 ? 0 : size;
|
||||||
|
}
|
||||||
} else if(handle->usedelta) {
|
} else if(handle->usedelta) {
|
||||||
off_t dltsize;
|
off_t dltsize;
|
||||||
|
|
||||||
|
@ -319,11 +335,16 @@ static int compute_download_size(alpm_pkg_t *newpkg)
|
||||||
size = newpkg->size;
|
size = newpkg->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finish:
|
||||||
_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",
|
||||||
(intmax_t)size, newpkg->name);
|
(intmax_t)size, newpkg->name);
|
||||||
|
|
||||||
newpkg->infolevel |= INFRQ_DSIZE;
|
newpkg->infolevel |= INFRQ_DSIZE;
|
||||||
newpkg->download_size = size;
|
newpkg->download_size = size;
|
||||||
|
|
||||||
|
FREE(fpath);
|
||||||
|
FREE(fnamepart);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue