/** Compute the size of the files that will be downloaded to install a * package. * @param newpkg the new package to upgrade to */ static int compute_download_size(alpm_pkg_t *newpkg) { const char *fname; char *fpath; off_t size = 0; alpm_handle_t *handle = newpkg->handle; if(newpkg->origin != PKG_FROM_SYNCDB) { newpkg->infolevel |= INFRQ_DSIZE; newpkg->download_size = 0; return 0; } fname = alpm_pkg_get_filename(newpkg); ASSERT(fname != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1)); fpath = _alpm_filecache_find(handle, fname); if(fpath) { FREE(fpath); size = 0; } else if(handle->usedelta) { off_t dltsize; off_t pkgsize = alpm_pkg_get_size(newpkg); dltsize = _alpm_shortest_delta_path(handle, alpm_pkg_get_deltas(newpkg), alpm_pkg_get_filename(newpkg), &newpkg->delta_path); if(newpkg->delta_path && (dltsize < pkgsize * MAX_DELTA_RATIO)) { _alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n"); size = dltsize; } else { _alpm_log(handle, ALPM_LOG_DEBUG, "using package size\n"); size = alpm_pkg_get_size(newpkg); alpm_list_free(newpkg->delta_path); newpkg->delta_path = NULL; } } else { size = alpm_pkg_get_size(newpkg); } _alpm_log(handle, ALPM_LOG_DEBUG, "setting download size %jd for pkg %s\n", (intmax_t)size, alpm_pkg_get_name(newpkg)); newpkg->infolevel |= INFRQ_DSIZE; newpkg->download_size = size; return 0; }
/** Compute the size of the files that will be downloaded to install a * package. * @param newpkg the new package to upgrade to */ static int compute_download_size(alpm_pkg_t *newpkg) { const char *fname; char *fpath, *fnamepart = NULL; off_t size = 0; alpm_handle_t *handle = newpkg->handle; int ret = 0; if(newpkg->origin != ALPM_PKG_FROM_SYNCDB) { newpkg->infolevel |= INFRQ_DSIZE; newpkg->download_size = 0; return 0; } ASSERT(newpkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1)); fname = newpkg->filename; fpath = _alpm_filecache_find(handle, fname); /* downloaded file exists, so there's nothing to grab */ if(fpath) { 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; } /* tell the caller that we have a partial */ ret = 1; } else if(handle->deltaratio > 0.0) { off_t dltsize; dltsize = _alpm_shortest_delta_path(handle, newpkg->deltas, newpkg->filename, &newpkg->delta_path); if(newpkg->delta_path && (dltsize < newpkg->size * handle->deltaratio)) { _alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n"); size = dltsize; } else { _alpm_log(handle, ALPM_LOG_DEBUG, "using package size\n"); size = newpkg->size; alpm_list_free(newpkg->delta_path); newpkg->delta_path = NULL; } } else { size = newpkg->size; } finish: _alpm_log(handle, ALPM_LOG_DEBUG, "setting download size %jd for pkg %s\n", (intmax_t)size, newpkg->name); newpkg->infolevel |= INFRQ_DSIZE; newpkg->download_size = size; FREE(fpath); FREE(fnamepart); return ret; }