# HG changeset patch # User Kristian H?gsberg # Date 1207585753 14400 # Node ID 60badcb3d8ead07b982962cd8282c01b34d9c980 # Parent e0047e89db072023896373080e9524b25abcb151 Handle http errors better. diff -r e0047e89db07 -r 60badcb3d8ea main.c --- a/main.c Mon Apr 07 12:09:50 2008 -0400 +++ b/main.c Mon Apr 07 12:29:13 2008 -0400 @@ -253,6 +253,7 @@ char error[256]; FILE *fp; CURLcode res; + long response; curl = curl_easy_init(); if (curl == NULL) @@ -274,6 +275,18 @@ unlink(file); return -1; } + res = curl_easy_getinfo(curl, + CURLINFO_RESPONSE_CODE, &response); + if (res != CURLE_OK) { + fprintf(stderr, "curl error: %s\n", error); + unlink(file); + return -1; + } + if (response != 200) { + fprintf(stderr, " - failed %ld\n", response); + unlink(file); + return -1; + } fprintf(stderr, "\n"); } @@ -480,6 +493,7 @@ { char file[PATH_MAX], url[256]; const char *v; + int *errors = data; if (old_version) return; @@ -496,7 +510,7 @@ snprintf(file, sizeof file, "rpms/%s-%s.%s.rpm", name, v, arch); if (download_if_missing(url, file) < 0) - fprintf(stderr, "failed to download %s\n", name); + (*errors)++; } static void @@ -583,7 +597,12 @@ razor_set_write_to_fd(next, fd); printf("wrote %s\n", new_path); - razor_set_diff(system, next, download_package, NULL); + razor_set_diff(system, next, download_package, &errors); + if (errors > 0) { + fprintf(stderr, "failed to download %d packages\n", errors); + unlink(new_path); + return 1; + } /* FIXME: We need to figure out the right install order here, * so the post and pre scripts can run. */ @@ -663,8 +682,7 @@ name, version, arch); snprintf(file, sizeof file, "rpms/%s-%s.%s.rpm", name, version, arch); - if (download_if_missing(url, file) < 0) - fprintf(stderr, "failed to download %s\n", name); + download_if_missing(url, file); } razor_package_iterator_destroy(pi); razor_set_destroy(set);