summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/dload.c
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-03-25 13:45:54 +0100
committerDan McGee <dan@archlinux.org>2011-03-28 03:14:10 +0200
commit33c08ac91e32e1c1fe135c42030f1a2b64a63a54 (patch)
tree1b7c480c624ecb6bf9c2d95c43330e7427a77dcd /lib/libalpm/dload.c
parentfd64988c8085a410a80851e2b4b6b62ea59139c2 (diff)
downloadpacman-33c08ac91e32e1c1fe135c42030f1a2b64a63a54.tar.gz
pacman-33c08ac91e32e1c1fe135c42030f1a2b64a63a54.tar.xz
lib/dload: code simplification
Based on the fact that localf always points to the same file, there's no need to code in multiple fopen calls with varying results. Instead, track the desired file open mode and make a single call to fopen. Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/dload.c')
-rw-r--r--lib/libalpm/dload.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 615177e6..49bb9bcc 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -147,10 +147,11 @@ static int curl_download_internal(const char *url, const char *localpath,
{
int ret = -1;
FILE *localf = NULL;
- char *useragent, *destfile, *tempfile;
+ const char *open_mode, *useragent;
+ char *destfile, *tempfile;
char hostname[256]; /* RFC1123 states applications should support this length */
struct stat st;
- long httpresp, timecond, remote_time, local_time;
+ long httpresp, timecond, remote_time;
double remote_size, bytes_dl;
struct sigaction sig_pipe[2], sig_int[2];
struct fileinfo dlfile;
@@ -185,30 +186,26 @@ static int curl_download_internal(const char *url, const char *localpath,
curl_easy_setopt(handle->curl, CURLOPT_USERAGENT, useragent);
}
+ /* TODO: no assuming here. the calling function should tell us what's kosher */
if(!force && stat(destfile, &st) == 0) {
/* assume its a sync, so we're starting from scratch. but, only download
* our local is out of date. */
- local_time = (long)st.st_mtime;
curl_easy_setopt(handle->curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- curl_easy_setopt(handle->curl, CURLOPT_TIMEVALUE, local_time);
+ curl_easy_setopt(handle->curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
} else if(stat(tempfile, &st) == 0 && st.st_size > 0) {
/* assume its a partial package download. we do not support resuming of
* transfers on partially downloaded sync DBs. */
- localf = fopen(tempfile, "ab");
+ open_mode = "ab";
curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, (long)st.st_size);
_alpm_log(PM_LOG_DEBUG, "tempfile found, attempting continuation");
dlfile.initial_size = (double)st.st_size;
}
- /* no destfile and no tempfile. start from scratch */
+ localf = fopen(tempfile, open_mode);
if(localf == NULL) {
- localf = fopen(tempfile, "wb");
- if(localf == NULL) {
- goto cleanup;
- }
+ goto cleanup;
}
- /* this has to be set _after_ figuring out which file we're opening */
curl_easy_setopt(handle->curl, CURLOPT_WRITEDATA, localf);
/* print proxy info for debug purposes */