← Commit list

b148863e7d

Joshua Rogers
Joshua Rogers
2026-09-20
SUCCESS Duration: 422s

Subject

tool_operate: clear the retry flag when the output file fails

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

src/tool_operate.c+11 -1
@@ -547,6 +547,7 @@ static CURLcode retrycheck(struct OperationConfig *config,
notef("Keeping %" CURL_FORMAT_CURL_OFF_T " bytes", outs->bytes);
if(fflush(outs->stream)) {
errorf("Failed to flush output file stream");
+ *retryp = FALSE;
return CURLE_WRITE_ERROR;
}
if(outs->bytes >= CURL_OFF_T_MAX - outs->init) {
@@ -554,6 +555,7 @@ static CURLcode retrycheck(struct OperationConfig *config,
"%" CURL_FORMAT_CURL_OFF_T " + "
"%" CURL_FORMAT_CURL_OFF_T ")",
outs->init, outs->bytes);
+ *retryp = FALSE;
return CURLE_WRITE_ERROR;
}
truncate = FALSE;
@@ -577,10 +579,15 @@ static CURLcode retrycheck(struct OperationConfig *config,
notef("Throwing away %" CURL_FORMAT_CURL_OFF_T " bytes", outs->bytes);
/* truncate file at the position where we started appending */
- if(toolx_ftruncate(fileno(outs->stream), outs->init)) {
+ if(
+#ifdef DEBUGBUILD
+ getenv("CURL_DBG_TRUNCATE_FAIL") ||
+#endif
+ toolx_ftruncate(fileno(outs->stream), outs->init)) {
/* when truncate fails, we cannot append as then we
create something strange, bail out */
errorf("Failed to truncate file");
+ *retryp = FALSE;
return CURLE_WRITE_ERROR;
}
/* now seek to the end of the file, the position where we
@@ -589,6 +596,7 @@ static CURLcode retrycheck(struct OperationConfig *config,
if(rc) {
errorf("Failed seeking to end of file");
+ *retryp = FALSE;
return CURLE_WRITE_ERROR;
}
outs->bytes = 0; /* clear for next round */
@@ -693,6 +701,8 @@ static CURLcode post_close_output(struct per_transfer *per,
/* Close the outs file */
if(outs->fopened && outs->stream) {
rc = curlx_fclose(outs->stream);
+ outs->stream = NULL;
+ outs->fopened = FALSE;
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
tests/data/Makefile.am+1 -0
@@ -1726,6 +1726,7 @@ TESTCASES = \
test1713 \
test1714 \
test1715 \
+ test1716 \
test1720 \
test1721 \
test1722 \
tests/data/test1716+54 -0
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+retry
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 503 Service Unavailable
+Content-Length: 6
+Connection: close
+
+-foo-
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<features>
+Debug
+</features>
+<setenv>
+CURL_DBG_TRUNCATE_FAIL=1
+</setenv>
+<name>
+--retry when the output file cannot be truncated
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER --retry 2 --retry-delay 0
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+23
+</errorcode>
+<protocol crlf="headers">
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+
+</protocol>
+</verify>
+</testcase>