static double query_total_download_size(struct list *list) { double ret; double size_sum = 0; struct file *file = NULL; char *untard_file = NULL; char *url = NULL; while (list) { file = list->data; list = list->next; string_or_die(&untard_file, "%s/%i/Manifest.%s", state_dir, file->last_change, file->filename); if (access(untard_file, F_OK) == -1) { /* Does not exist client-side. Must download */ string_or_die(&url, "%s/%i/Manifest.%s.tar", content_url, file->last_change, file->filename); ret = swupd_curl_query_content_size(url); free_string(&url); if (ret != -1) { /* Convert file size from bytes to MB */ ret = ret / 1000000; size_sum += ret; } else { free_string(&untard_file); return ret; } } free_string(&untard_file); } return size_sum; }
static double fullfile_query_total_download_size(struct list *files) { double size = 0; double total_size = 0; struct file *file = NULL; struct list *list = NULL; char *url = NULL; int count = 0; for (list = list_head(files); list; list = list->next) { file = list->data; /* if it is a file from a mix, we won't download it */ if (file->is_mix) { continue; } string_or_die(&url, "%s/%i/files/%s.tar", content_url, file->last_change, file->hash); size = swupd_curl_query_content_size(url); if (size != -1) { total_size += size; } else { debug("The header for file %s could not be downloaded\n", file->filename); free_string(&url); return -SWUPD_COULDNT_DOWNLOAD_FILE; } count++; debug("File: %s (%.2lf Mb)\n", url, size / 1000000); free_string(&url); } debug("Number of files to download: %d\n", count); debug("Total size of files to be downloaded: %.2lf Mb\n", total_size / 1000000); return total_size; }