diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -154,16 +154,17 @@ int curlget(char *url, char *out){ curl = curl_easy_init(); if(curl) { - outfile = fopen(out, "w"); // Open where we're writing to - - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat. - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress); - curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar); - res = curl_easy_perform(curl); - curl_easy_cleanup(curl); + outfile = fopen(out, "w"); // Open where we're writing to + if(outfile == NULL) + return 2; // Output dir doesn't exist + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat. + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar); + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); } fprintf(stderr,"\n"); // Clears out he progressbar's carriage return return res; // 0 is OK, 1 is 404 or other error @@ -365,21 +366,28 @@ int downloadTar(char *url, char *destina if(fstatus == -1) { // Download the Tar - if( curlget(url, destinationPath) == 0){ + int ret = curlget(url, destinationPath); + if(ret == 0){ fprintf(stderr, "Job data retrieved successfully\n"); // free(url); @FIXME: causes doublefree! Curl must free the url? return 0; } - else { + else if(ret == 1){ fprintf(stderr, "Downloading job data from %s failed. Check your network connection.\n",url); free(url); return 1; // Eventually make a retry loop } + else if(ret == 2){ + fprintf(stderr, "Output directory \"%s\" does not exist!\n",destinationPath); + free(url); + return 3; + } } else{ fprintf(stderr, "Tar already exists! Download cancelled.\n"); return 2; } + }