Subject: Re: [PATCH 07/11] Resumable clone: add resumable download to http/curl

From: Junio C Hamano <[email-masked]>
Date: Fri, 16 Sep 2016 15:45:44 -0700

Kevin Wern <[email-masked]> writes:

> +int http_download_primer(const char *url, const char *out_file)
> +{
> +	int ret = 0, try_count = HTTP_TRY_COUNT;
> +	struct http_get_options options = {0};
> +	options.progress = 1;
> +
> +	if (file_exists(out_file)) {
> +		fprintf(stderr,
> +			"File already downloaded: '%s', skipping...\n",
> +			out_file);
> +		return ret;
> +	}
> +
> +	do {
> +		if (try_count != HTTP_TRY_COUNT) {
> +			fprintf(stderr, "Connection interrupted for some "
> +				"reason, retrying (%d attempts left)\n",
> +				try_count);
> +			struct timeval time = {10, 0}; // 1s

We do not use // comment.

> +			select(0, NULL, NULL, NULL, &time);
> +		}
> +		ret = http_get_file(url, out_file, &options);

I didn't realize that http_get_file() -> http_request() codepath,
when it is the output file, already can do the "ftell and request
the reminder".  Very nice.

> @@ -1136,7 +1138,10 @@ static int handle_curl_result(struct slot_results *results)
>  				curl_easy_strerror(results->curl_result),
>  				sizeof(curl_errorstr));
>  #endif
> -		return HTTP_ERROR;
> +		if (results->http_code >= 400)
> +			return HTTP_ERROR;
> +		else
> +			return HTTP_ERROR_RESUMABLE;
>  	}
>  }

Hmm, is "anything below 400" a good definition of resumable errors?