1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-10-31 15:45:03 -04:00

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>
This commit is contained in:
Dave Reisner 2011-03-25 08:37:02 -04:00 committed by Dan McGee
parent 55f790ebe4
commit fd64988c80

View File

@ -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. */