Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool_operate: don't make a failed etag save a fatal error #7945

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 77 additions & 69 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,65 +800,13 @@ static CURLcode single_transfer(struct GlobalConfig *global,
struct OutStruct *heads;
struct OutStruct *etag_save;
struct HdrCbData *hdrcbdata = NULL;
CURL *curl = curl_easy_init();
result = add_per_transfer(&per);
if(result || !curl) {
curl_easy_cleanup(curl);
result = CURLE_OUT_OF_MEMORY;
break;
}
if(state->uploadfile) {
per->uploadfile = strdup(state->uploadfile);
if(!per->uploadfile) {
curl_easy_cleanup(curl);
result = CURLE_OUT_OF_MEMORY;
break;
}
}
*added = TRUE;
per->config = config;
per->curl = curl;
per->urlnum = urlnode->num;

/* default headers output stream is stdout */
heads = &per->heads;
heads->stream = stdout;
struct OutStruct etag_first;
CURL *curl;

/* Single header file for all URLs */
if(config->headerfile) {
/* open file for output: */
if(strcmp(config->headerfile, "-")) {
FILE *newfile;
newfile = fopen(config->headerfile, per->prev == NULL?"wb":"ab");
if(!newfile) {
warnf(global, "Failed to open %s\n", config->headerfile);
result = CURLE_WRITE_ERROR;
break;
}
else {
heads->filename = config->headerfile;
heads->s_isreg = TRUE;
heads->fopened = TRUE;
heads->stream = newfile;
}
}
else {
/* always use binary mode for protocol header output */
set_binmode(heads->stream);
}
}

hdrcbdata = &per->hdrcbdata;

outs = &per->outs;
input = &per->input;

per->outfile = NULL;
per->infdopen = FALSE;
per->infd = STDIN_FILENO;

/* default output stream is stdout */
outs->stream = stdout;
/* --etag-save */
memset(&etag_first, 0, sizeof(etag_first));
etag_save = &etag_first;
etag_save->stream = stdout;

/* --etag-compare */
if(config->etag_compare_file) {
Expand Down Expand Up @@ -901,21 +849,16 @@ static CURLcode single_transfer(struct GlobalConfig *global,
}
}

/* --etag-save */
etag_save = &per->etag_save;
etag_save->stream = stdout;

if(config->etag_save_file) {
/* open file for output: */
if(strcmp(config->etag_save_file, "-")) {
FILE *newfile = fopen(config->etag_save_file, "wb");
if(!newfile) {
warnf(
global,
"Failed to open %s\n", config->etag_save_file);

result = CURLE_WRITE_ERROR;
break;
warnf(global, "Failed creating file for saving etags: \"%s\". "
"Skip this transfer\n", config->etag_save_file);
Curl_safefree(state->outfiles);
glob_cleanup(state->urls);
return CURLE_OK;
}
else {
etag_save->filename = config->etag_save_file;
Expand All @@ -930,6 +873,67 @@ static CURLcode single_transfer(struct GlobalConfig *global,
}
}

curl = curl_easy_init();
result = add_per_transfer(&per);
if(result || !curl) {
curl_easy_cleanup(curl);
result = CURLE_OUT_OF_MEMORY;
break;
}
if(state->uploadfile) {
per->uploadfile = strdup(state->uploadfile);
if(!per->uploadfile) {
curl_easy_cleanup(curl);
result = CURLE_OUT_OF_MEMORY;
break;
}
}
*added = TRUE;
per->config = config;
per->curl = curl;
per->urlnum = urlnode->num;
per->etag_save = etag_first; /* copy the whole struct */

/* default headers output stream is stdout */
heads = &per->heads;
heads->stream = stdout;

/* Single header file for all URLs */
if(config->headerfile) {
/* open file for output: */
if(strcmp(config->headerfile, "-")) {
FILE *newfile;
newfile = fopen(config->headerfile, per->prev == NULL?"wb":"ab");
if(!newfile) {
warnf(global, "Failed to open %s\n", config->headerfile);
result = CURLE_WRITE_ERROR;
break;
}
else {
heads->filename = config->headerfile;
heads->s_isreg = TRUE;
heads->fopened = TRUE;
heads->stream = newfile;
}
}
else {
/* always use binary mode for protocol header output */
set_binmode(heads->stream);
}
}

hdrcbdata = &per->hdrcbdata;

outs = &per->outs;
input = &per->input;

per->outfile = NULL;
per->infdopen = FALSE;
per->infd = STDIN_FILENO;

/* default output stream is stdout */
outs->stream = stdout;

if(state->urls) {
result = glob_next_url(&per->this_url, state->urls);
if(result)
Expand Down Expand Up @@ -2305,8 +2309,12 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
bool added = FALSE;

result = create_transfer(global, share, &added);
if(result || !added)
if(result)
return result;
if(!added) {
errorf(global, "no transfer performed\n");
return CURLE_READ_ERROR;
}
for(per = transfers; per;) {
bool retry;
long delay;
Expand Down
3 changes: 2 additions & 1 deletion tests/data/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ test325 test326 test327 test328 test329 test330 test331 test332 test333 \
test334 test335 test336 test337 test338 test339 test340 test341 test342 \
test343 test344 test345 test346 test347 test348 test349 test350 test351 \
test352 test353 test354 test355 test356 test357 test358 test359 test360 \
test361 test362 test363 test364 test365 test366 test367 test368 \
test361 test362 test363 test364 test365 test366 test367 test368 test369 \
test370 \
\
test392 test393 test394 test395 test396 test397 \
\
Expand Down
47 changes: 47 additions & 0 deletions tests/data/test369
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<testcase>
<info>
<keywords>
HTTP
HTTP GET
etag
</keywords>
</info>

#
# Server-side
<reply>
<data>
HTTP/1.1 200 OK
Content-Length: 4
Content-Type: text/html

hej
</data>
</reply>

#
# Client-side
<client>
<server>
http
</server>
<name>
--etag-save with bad path then working transfer
</name>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER --etag-save log/nowhere/etag%TESTNUMBER --next http://%HOSTIP:%HTTPPORT/%TESTNUMBER --include --output log/curl%TESTNUMBER.out
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>
<protocol>
GET /%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT
User-Agent: curl/%VERSION
Accept: */*

</protocol>
</verify>
</testcase>
36 changes: 36 additions & 0 deletions tests/data/test370
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<testcase>
<info>
<keywords>
HTTP
HTTP GET
etag
</keywords>
</info>

#
# Server-side
<reply>
</reply>

#
# Client-side
<client>
<server>
none
</server>
<name>
--etag-save with bad path - no transfer
</name>
<command>
http://%HOSTIP:%NOLISTENPORT/%TESTNUMBER --etag-save log/nowhere/etag%TESTNUMBER
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>
<errorcode>
26
</errorcode>
</verify>
</testcase>