index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dave Reisner <d@falconindy.com> | 2011-03-25 08:37:02 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-03-27 20:12:51 -0500 |
commit | fd64988c8085a410a80851e2b4b6b62ea59139c2 (patch) | |
tree | 983801d9cc7f0e0627a54b2d28e8263fb2e977a5 /lib | |
parent | 55f790ebe49ebf5a7d2084682735fd75f6d4903b (diff) |
-rw-r--r-- | lib/libalpm/dload.c | 33 |
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 482cf11d..615177e6 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -56,26 +56,16 @@ static char *get_filename(const char *url) } #ifdef HAVE_LIBCURL -static char *get_destfile(const char *path, const char *filename) +static char *get_fullpath(const char *path, const char *filename, + const char *suffix) { - char *destfile; - /* len = localpath len + filename len + null */ - size_t len = strlen(path) + strlen(filename) + 1; - CALLOC(destfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL)); - snprintf(destfile, len, "%s%s", path, filename); + char *filepath; + /* len = localpath len + filename len + suffix len + null */ + size_t len = strlen(path) + strlen(filename) + strlen(suffix) + 1; + CALLOC(filepath, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL)); + snprintf(filepath, len, "%s%s%s", path, filename, suffix); - return destfile; -} - -static char *get_tempfile(const char *path, const char *filename) -{ - char *tempfile; - /* len = localpath len + filename len + '.part' len + null */ - size_t len = strlen(path) + strlen(filename) + 6; - CALLOC(tempfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL)); - snprintf(tempfile, len, "%s%s.part", path, filename); - - return tempfile; + return filepath; } #define check_stop() if(dload_interrupted) { ret = -1; goto cleanup; } @@ -172,8 +162,11 @@ static int curl_download_internal(const char *url, const char *localpath, RET_ERR(PM_ERR_SERVER_BAD_URL, -1); } - destfile = get_destfile(localpath, dlfile.filename); - tempfile = get_tempfile(localpath, dlfile.filename); + destfile = get_fullpath(localpath, dlfile.filename, ""); + tempfile = get_fullpath(localpath, dlfile.filename, ".part"); + if(!destfile || !tempfile) { + goto cleanup; + } /* the curl_easy handle is initialized with the alpm handle, so we only need * to reset the curl handle set parameters for each time it's used. */ |