mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 21:38:19 -05:00
use strreplace in the xfercommand code
this operation was re-implemented using static strings, instead of using the existing strreplace function Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
2f19072632
commit
cb1d4195bf
@ -633,9 +633,7 @@ int download_with_xfercommand(const char *url, const char *localpath,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
int retval;
|
int retval;
|
||||||
int usepart = 0;
|
int usepart = 0;
|
||||||
char *ptr1, *ptr2;
|
char *parsedcmd,*tempcmd;
|
||||||
char origCmd[PATH_MAX];
|
|
||||||
char parsedCmd[PATH_MAX] = "";
|
|
||||||
char cwd[PATH_MAX];
|
char cwd[PATH_MAX];
|
||||||
char *destfile, *tempfile, *filename;
|
char *destfile, *tempfile, *filename;
|
||||||
|
|
||||||
@ -650,28 +648,18 @@ int download_with_xfercommand(const char *url, const char *localpath,
|
|||||||
destfile = get_destfile(localpath, filename);
|
destfile = get_destfile(localpath, filename);
|
||||||
tempfile = get_tempfile(localpath, filename);
|
tempfile = get_tempfile(localpath, filename);
|
||||||
|
|
||||||
strncpy(origCmd, config->xfercommand, sizeof(origCmd));
|
tempcmd = strdup(config->xfercommand);
|
||||||
/* replace all occurrences of %o with fn.part */
|
/* replace all occurrences of %o with fn.part */
|
||||||
ptr1 = origCmd;
|
if(strstr(tempcmd, "%o")) {
|
||||||
while((ptr2 = strstr(ptr1, "%o"))) {
|
|
||||||
usepart = 1;
|
usepart = 1;
|
||||||
ptr2[0] = '\0';
|
parsedcmd = strreplace(tempcmd, "%o", tempfile);
|
||||||
strcat(parsedCmd, ptr1);
|
free(tempcmd);
|
||||||
strcat(parsedCmd, tempfile);
|
tempcmd = parsedcmd;
|
||||||
ptr1 = ptr2 + 2;
|
|
||||||
}
|
}
|
||||||
strcat(parsedCmd, ptr1);
|
|
||||||
/* replace all occurrences of %u with the download URL */
|
/* replace all occurrences of %u with the download URL */
|
||||||
strncpy(origCmd, parsedCmd, sizeof(origCmd));
|
parsedcmd = strreplace(tempcmd, "%u", url);
|
||||||
parsedCmd[0] = '\0';
|
free(tempcmd);
|
||||||
ptr1 = origCmd;
|
|
||||||
while((ptr2 = strstr(ptr1, "%u"))) {
|
|
||||||
ptr2[0] = '\0';
|
|
||||||
strcat(parsedCmd, ptr1);
|
|
||||||
strcat(parsedCmd, url);
|
|
||||||
ptr1 = ptr2 + 2;
|
|
||||||
}
|
|
||||||
strcat(parsedCmd, ptr1);
|
|
||||||
/* cwd to the download directory */
|
/* cwd to the download directory */
|
||||||
getcwd(cwd, PATH_MAX);
|
getcwd(cwd, PATH_MAX);
|
||||||
if(chdir(localpath)) {
|
if(chdir(localpath)) {
|
||||||
@ -680,8 +668,8 @@ int download_with_xfercommand(const char *url, const char *localpath,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
/* execute the parsed command via /bin/sh -c */
|
/* execute the parsed command via /bin/sh -c */
|
||||||
pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedCmd);
|
pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedcmd);
|
||||||
retval = system(parsedCmd);
|
retval = system(parsedcmd);
|
||||||
|
|
||||||
if(retval == -1) {
|
if(retval == -1) {
|
||||||
pm_printf(PM_LOG_WARNING, "running XferCommand: fork failed!\n");
|
pm_printf(PM_LOG_WARNING, "running XferCommand: fork failed!\n");
|
||||||
@ -707,6 +695,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
free(destfile);
|
free(destfile);
|
||||||
free(tempfile);
|
free(tempfile);
|
||||||
|
free(parsedcmd);
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user