summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-03-25 13:37:02 +0100
committerDan McGee <dan@archlinux.org>2011-03-28 03:12:51 +0200
commitfd64988c8085a410a80851e2b4b6b62ea59139c2 (patch)
tree983801d9cc7f0e0627a54b2d28e8263fb2e977a5 /lib/libalpm
parent55f790ebe49ebf5a7d2084682735fd75f6d4903b (diff)
downloadpacman-fd64988c8085a410a80851e2b4b6b62ea59139c2.tar.gz
pacman-fd64988c8085a410a80851e2b4b6b62ea59139c2.tar.xz
lib/dload: merge get_{destfile,tempfile} into get_fullpath
Create a more general function that allows appending a suffix to a filepath. Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/dload.c33
1 files changed, 13 insertions, 20 deletions
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. */