main.c
changeset 204 60badcb3d8ea
parent 203 e0047e89db07
child 205 bb1a6b6578a9
     1.1 --- a/main.c	Mon Apr 07 12:09:50 2008 -0400
     1.2 +++ b/main.c	Mon Apr 07 12:29:13 2008 -0400
     1.3 @@ -253,6 +253,7 @@
     1.4  	char error[256];
     1.5  	FILE *fp;
     1.6  	CURLcode res;
     1.7 +	long response;
     1.8  
     1.9  	curl = curl_easy_init();
    1.10  	if (curl == NULL)
    1.11 @@ -274,6 +275,18 @@
    1.12  			unlink(file);
    1.13  			return -1;
    1.14  		}
    1.15 +		res = curl_easy_getinfo(curl,
    1.16 +					CURLINFO_RESPONSE_CODE, &response);
    1.17 +		if (res != CURLE_OK) {
    1.18 +			fprintf(stderr, "curl error: %s\n", error);
    1.19 +                        unlink(file);
    1.20 +                        return -1;
    1.21 +		}
    1.22 +		if (response != 200) {
    1.23 +			fprintf(stderr, " - failed %ld\n", response);
    1.24 +                        unlink(file);
    1.25 +                        return -1;
    1.26 +		}
    1.27  		fprintf(stderr, "\n");
    1.28  	}
    1.29  
    1.30 @@ -480,6 +493,7 @@
    1.31  {
    1.32  	char file[PATH_MAX], url[256];
    1.33  	const char *v;
    1.34 +	int *errors = data;
    1.35  
    1.36  	if (old_version)
    1.37  		return;
    1.38 @@ -496,7 +510,7 @@
    1.39  	snprintf(file, sizeof file,
    1.40  		 "rpms/%s-%s.%s.rpm", name, v, arch);
    1.41  	if (download_if_missing(url, file) < 0)
    1.42 -		fprintf(stderr, "failed to download %s\n", name);
    1.43 +		(*errors)++;
    1.44  }
    1.45  
    1.46  static void
    1.47 @@ -583,7 +597,12 @@
    1.48  	razor_set_write_to_fd(next, fd);
    1.49  	printf("wrote %s\n", new_path);
    1.50  
    1.51 -	razor_set_diff(system, next, download_package, NULL);	
    1.52 +	razor_set_diff(system, next, download_package, &errors);
    1.53 +	if (errors > 0) {
    1.54 +		fprintf(stderr, "failed to download %d packages\n", errors);
    1.55 +		unlink(new_path);
    1.56 +                return 1;
    1.57 +        }
    1.58  
    1.59  	/* FIXME: We need to figure out the right install order here,
    1.60  	 * so the post and pre scripts can run. */
    1.61 @@ -663,8 +682,7 @@
    1.62  			 name, version, arch);
    1.63  		snprintf(file, sizeof file,
    1.64  			 "rpms/%s-%s.%s.rpm", name, version, arch);
    1.65 -		if (download_if_missing(url, file) < 0)
    1.66 -			fprintf(stderr, "failed to download %s\n", name);
    1.67 +		download_if_missing(url, file);
    1.68  	}
    1.69  	razor_package_iterator_destroy(pi);
    1.70  	razor_set_destroy(set);