diff options
author | Aurelien Foret <aurelien@archlinux.org> | 2005-03-20 21:41:19 +0000 |
---|---|---|
committer | Aurelien Foret <aurelien@archlinux.org> | 2005-03-20 21:41:19 +0000 |
commit | a65f6aef48ab50000c9f73892c742cf6ff5387db (patch) | |
tree | 125eaa22b16ae09b2ae611a4a0d0cafba1d5dba9 | |
parent | 1b7b6e47a1af43af319b5bf758e28cecc2ba5ca1 (diff) | |
download | pacman-a65f6aef48ab50000c9f73892c742cf6ff5387db.tar.xz |
fetch_pkgurl: do not download a file if it's already in the current dir
-rw-r--r-- | src/pacman/download.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/pacman/download.c b/src/pacman/download.c index efd40fbf..cd5888fe 100644 --- a/src/pacman/download.c +++ b/src/pacman/download.c @@ -495,13 +495,8 @@ char *fetch_pkgurl(char *target) { char spath[PATH_MAX]; char url[PATH_MAX]; - server_t *server; - list_t *servers = NULL; - list_t *files = NULL; char *host, *path, *fn; - - /* ORE - do not download the file if it exists in the current dir */ + struct stat buf; strncpy(url, target, PATH_MAX); host = strstr(url, "://"); @@ -524,25 +519,35 @@ char *fetch_pkgurl(char *target) strcpy(spath, "/"); } - server = (server_t *)malloc(sizeof(server_t)); - if(server == NULL) { - fprintf(stderr, "error: failed to allocate %d bytes\n", sizeof(server_t)); - return(NULL); - } - server->protocol = url; - server->server = host; - server->path = spath; - servers = list_add(servers, server); - - files = list_add(files, fn); - if(downloadfiles(servers, ".", files)) { - fprintf(stderr, "error: failed to download %s\n", target); - return(NULL); - } + /* do not download the file if it exists in the current dir + */ + if(stat(fn, &buf) == 0) { + vprint(" %s is already in the current directory\n", fn); + } else { + server_t *server; + list_t *servers = NULL; + list_t *files = NULL; + + server = (server_t *)malloc(sizeof(server_t)); + if(server == NULL) { + fprintf(stderr, "error: failed to allocate %d bytes\n", sizeof(server_t)); + return(NULL); + } + server->protocol = url; + server->server = host; + server->path = spath; + servers = list_add(servers, server); + + files = list_add(files, fn); + if(downloadfiles(servers, ".", files)) { + fprintf(stderr, "error: failed to download %s\n", target); + return(NULL); + } + files->data = NULL; + FREELIST(files); - FREELIST(servers); - files->data = NULL; - FREELIST(files); + FREELIST(servers); + } /* return the target with the raw filename, no URL */ return(strndup(fn, PATH_MAX)); |