[pacman-dev] [PATCH] Add a fetch callback to allow front-end download support
Sebastian Nowicki
sebnow at gmail.com
Sat Apr 4 04:30:11 EDT 2009
I fixed the warnings and errors and tested it a bit more. Everything
seems to be working fine. Using dynamic allocation for the xfercommand
string removed the problem with PATH_MAX. The previously inlined
functions are now separate functions as before, with minor changes due
to the lack of macros from libalpm (see diff below).
On Sun, Mar 29, 2009 at 5:34 AM, Dan McGee <dpmcgee at gmail.com> wrote:
> On Fri, Feb 20, 2009 at 2:31 AM, Sebastian Nowicki <sebnow at gmail.com> wrote:
>> diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
>> index 59916d6..0d6c897 100644
>> --- a/src/pacman/pacman.c
>> +++ b/src/pacman/pacman.c
>> @@ -573,6 +573,99 @@ static void setrepeatingoption(const char *ptr, const char *option,
>> pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, p);
>> }
>>
>> +/** External fetch callback */
>> +static int _download_with_xfercommand(const char *url, const char *localpath,
>> + time_t mtimeold, time_t *mtimenew) {
> Kill the underscore in the function name- the only reason
> _parseconfig() has it is because it is an internal loop of
> parseconfig(). In addition, I don't think you can make this static as
> we are attempting to pass a function pointer to the backend, and
> static could potentially cause it to be dropped and/or inlined.
I wasn't sure about that either, but it worked as static. I changed it
to non-static to be on the safe side.
On Sat, Apr 4, 2009 at 1:48 AM, Dan McGee <dpmcgee at gmail.com> wrote:
> I'll try to do a comparison diff sometime to see what changed once you
> resubmit the patch.
Here's a diff of the functions moved over:
--- a 2009-04-04 16:13:57.000000000 +0800
+++ b 2009-04-04 16:14:45.000000000 +0800
@@ -10,7 +10,7 @@ static char *get_destfile(const char *pa
char *destfile;
/* len = localpath len + filename len + null */
int len = strlen(path) + strlen(filename) + 1;
- CALLOC(destfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
+ destfile = calloc(len, sizeof(char));
snprintf(destfile, len, "%s%s", path, filename);
return(destfile);
@@ -20,13 +20,13 @@ static char *get_tempfile(const char *pa
char *tempfile;
/* len = localpath len + filename len + '.part' len + null */
int len = strlen(path) + strlen(filename) + 6;
- CALLOC(tempfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
+ tempfile = calloc(len, sizeof(char));
snprintf(tempfile, len, "%s%s.part", path, filename);
return(tempfile);
}
-static int download_external(const char *url, const char *localpath,
+int download_with_xfercommand(const char *url, const char *localpath,
time_t mtimeold, time_t *mtimenew) {
int ret = 0;
int retval;
@@ -37,19 +37,19 @@ static int download_external(const char
char cwd[PATH_MAX];
char *destfile, *tempfile, *filename;
- if(!handle->xfercommand) {
- RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
+ if(!config->xfercommand) {
+ return -1;
}
filename = get_filename(url);
if(!filename) {
- RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
+ return -1;
}
destfile = get_destfile(localpath, filename);
tempfile = get_tempfile(localpath, filename);
+ strncpy(origCmd, config->xfercommand, sizeof(origCmd));
/* replace all occurrences of %o with fn.part */
- strncpy(origCmd, handle->xfercommand, sizeof(origCmd));
ptr1 = origCmd;
while((ptr2 = strstr(ptr1, "%o"))) {
usepart = 1;
@@ -73,22 +73,20 @@ static int download_external(const char
/* cwd to the download directory */
getcwd(cwd, PATH_MAX);
if(chdir(localpath)) {
- _alpm_log(PM_LOG_WARNING, _("could not chdir to %s\n"), localpath);
- pm_errno = PM_ERR_EXTERNAL_DOWNLOAD;
+ pm_printf(PM_LOG_DEBUG, "could not chdir to %s\n", localpath);
ret = -1;
goto cleanup;
}
/* execute the parsed command via /bin/sh -c */
- _alpm_log(PM_LOG_DEBUG, "running command: %s\n", parsedCmd);
+ pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedCmd);
retval = system(parsedCmd);
if(retval == -1) {
- _alpm_log(PM_LOG_WARNING, _("running XferCommand: fork failed!\n"));
- pm_errno = PM_ERR_EXTERNAL_DOWNLOAD;
+ pm_printf(PM_LOG_DEBUG, "running XferCommand: fork failed!\n");
ret = -1;
} else if(retval != 0) {
/* download failed */
- _alpm_log(PM_LOG_DEBUG, "XferCommand command returned non-zero status "
+ pm_printf(PM_LOG_DEBUG, "XferCommand command returned non-zero status "
"code (%d)\n", retval);
ret = -1;
} else {
@@ -105,8 +103,8 @@ cleanup:
/* hack to let an user the time to cancel a download */
sleep(2);
}
- FREE(destfile);
- FREE(tempfile);
+ free(destfile);
+ free(tempfile);
return(ret);
}
More information about the pacman-dev
mailing list