← Commit list

30107badd5

Daniel Stenberg
Daniel Stenberg
2026-09-03
SUCCESS Duration: 422s

Subject

tool_cb_wrt: try up to .9999 when no-clobbering

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 →

docs/cmdline-opts/no-clobber.md+1 -1
@@ -18,7 +18,7 @@ Example:
When used in conjunction with the --output, --remote-header-name,
--remote-name, or --remote-name-all options, curl avoids overwriting files
that already exist. Instead, a dot and a number gets appended to the name of
-the file that would be created, up to filename.100 after which it does not
+the file that would be created, up to filename.9999 after which it does not
create any file.
Note that this is the negated option name documented. You can thus use
src/tool_cb_wrt.c+16 -2
@@ -34,6 +34,8 @@
#define OPENMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
#endif
+#define MAX_CLOBBER_ATTEMPTS 9999
+
/* create/open a local file for writing, return TRUE on success */
bool tool_create_output_file(struct OutStruct *outs,
struct OperationConfig *config)
@@ -62,12 +64,24 @@ bool tool_create_output_file(struct OutStruct *outs,
int next_num = 1;
struct dynbuf fbuffer;
char *newfile;
+ int max_num = MAX_CLOBBER_ATTEMPTS;
+#ifdef DEBUGBUILD
+ char *p = curl_getenv("CURL_MAX_CLOBBER");
+ if(p) {
+ const char *pp = p;
+ curl_off_t val;
+ if(!curlx_str_number(&pp, &val, 100000))
+ max_num = (int)val;
+ curl_free(p);
+ }
+#endif
curlx_dyn_init(&fbuffer, 1025);
/* !checksrc! disable ERRNOVAR 1 */
while(fd == -1 && /* have not successfully opened a file */
- (errno == EEXIST || errno == EISDIR) &&
/* because we keep having files that already exist */
- next_num < 100 /* and we have not reached the retry limit */) {
+ (errno == EEXIST || errno == EISDIR) &&
+ /* and we have not reached the retry limit */
+ (next_num < max_num)) {
curlx_dyn_reset(&fbuffer);
if(curlx_dyn_addf(&fbuffer, "%s.%d", fname, next_num))
return FALSE;
tests/data/test1683+4 -0
@@ -30,7 +30,11 @@ http
</server>
<features>
http
+Debug
</features>
+<setenv>
+CURL_MAX_CLOBBER=100
+</setenv>
<command option="no-output">
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -o %LOGDIR/exist%TESTNUMBER --no-clobber
</command>