From 49472a3a8ff731dcccd8099c4070119426c49145 Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 7 Mar 2007 01:25:23 +0000 Subject: various checks & cleanups, default usage, hook script Add file valid checks to update Add file checks to parse contents Remove empty files which don't download Automatically attempt to update contents if they cannot be opened Add default showopts if no options are passed Remove show struct mention in usage Move order of usage Add alternative media toc file option Added commit hook script git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-6 --- download.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'download.c') diff --git a/download.c b/download.c index 099a65f..6e83afb 100644 --- a/download.c +++ b/download.c @@ -44,7 +44,7 @@ extern char proxy_user[STR_MAX]; extern char proxy_pass[STR_MAX]; extern CURL *main_curl_handle; -void save_file(CURL *curl_handle, char *url, char *filepath) +int save_file(CURL *curl_handle, char *url, char *filepath) /* Save the file *url to *filepath */ { printf("Downloading %s\n",url); @@ -55,7 +55,10 @@ void save_file(CURL *curl_handle, char *url, char *filepath) if(curl_handle) { FILE *file; if((file = fopen(filepath,"w")) == NULL) + { fprintf(stderr,"Error: cannot open file %s for writing.\n",filepath); + return 1; + } curl_easy_setopt(curl_handle, CURLOPT_URL, url); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_func); @@ -98,7 +101,11 @@ void save_file(CURL *curl_handle, char *url, char *filepath) curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, update_progress); if(curl_easy_perform(curl_handle)) + { + remove(filepath); fprintf(stderr,"Error, could not download %s\n",url); + return 1; + } /* double d; curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &d); @@ -117,7 +124,9 @@ void save_file(CURL *curl_handle, char *url, char *filepath) else { fprintf(stderr,"Error: curl failed to initialise.\n"); printf("Could not download %s\n",url); + return 1; } + return 0; } int update_progress(void *data, double dltotal, double dlnow, -- cgit v1.2.3