1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-16 14:25:21 -05:00

fetch_pkgurl: do not download a file if it's already in the current dir

This commit is contained in:
Aurelien Foret 2005-03-20 21:41:19 +00:00
parent 1b7b6e47a1
commit a65f6aef48

View File

@ -495,13 +495,8 @@ char *fetch_pkgurl(char *target)
{ {
char spath[PATH_MAX]; char spath[PATH_MAX];
char url[PATH_MAX]; char url[PATH_MAX];
server_t *server;
list_t *servers = NULL;
list_t *files = NULL;
char *host, *path, *fn; char *host, *path, *fn;
struct stat buf;
/* ORE
do not download the file if it exists in the current dir */
strncpy(url, target, PATH_MAX); strncpy(url, target, PATH_MAX);
host = strstr(url, "://"); host = strstr(url, "://");
@ -524,25 +519,35 @@ char *fetch_pkgurl(char *target)
strcpy(spath, "/"); strcpy(spath, "/");
} }
server = (server_t *)malloc(sizeof(server_t)); /* do not download the file if it exists in the current dir
if(server == NULL) { */
fprintf(stderr, "error: failed to allocate %d bytes\n", sizeof(server_t)); if(stat(fn, &buf) == 0) {
return(NULL); vprint(" %s is already in the current directory\n", fn);
} } else {
server->protocol = url; server_t *server;
server->server = host; list_t *servers = NULL;
server->path = spath; list_t *files = NULL;
servers = list_add(servers, server);
files = list_add(files, fn); server = (server_t *)malloc(sizeof(server_t));
if(downloadfiles(servers, ".", files)) { if(server == NULL) {
fprintf(stderr, "error: failed to download %s\n", target); fprintf(stderr, "error: failed to allocate %d bytes\n", sizeof(server_t));
return(NULL); return(NULL);
} }
server->protocol = url;
server->server = host;
server->path = spath;
servers = list_add(servers, server);
FREELIST(servers); files = list_add(files, fn);
files->data = NULL; if(downloadfiles(servers, ".", files)) {
FREELIST(files); fprintf(stderr, "error: failed to download %s\n", target);
return(NULL);
}
files->data = NULL;
FREELIST(files);
FREELIST(servers);
}
/* return the target with the raw filename, no URL */ /* return the target with the raw filename, no URL */
return(strndup(fn, PATH_MAX)); return(strndup(fn, PATH_MAX));