mirror of
https://github.com/curl/curl.git
synced 2026-07-03 22:27:20 +03:00
tool_cb_wrt: fix no-clobber error handling
When saving a file with --no-clobber, make sure the existing file name remains set when creating the name fails. In a retry scenario, it comes back and uses that variable again. Add test 3036 to verify. Reported-by: James Fuller Closes #20939
This commit is contained in:
parent
3525ed9b2f
commit
29cb750fc2
3 changed files with 69 additions and 3 deletions
|
|
@ -61,6 +61,7 @@ bool tool_create_output_file(struct OutStruct *outs,
|
|||
if(config->file_clobber_mode == CLOBBER_NEVER && fd == -1) {
|
||||
int next_num = 1;
|
||||
struct dynbuf fbuffer;
|
||||
char *newfile;
|
||||
curlx_dyn_init(&fbuffer, 1025);
|
||||
/* !checksrc! disable ERRNOVAR 1 */
|
||||
while(fd == -1 && /* have not successfully opened a file */
|
||||
|
|
@ -78,8 +79,11 @@ bool tool_create_output_file(struct OutStruct *outs,
|
|||
/* Keep retrying in the hope that it is not interrupted sometime */
|
||||
} while(fd == -1 && errno == EINTR);
|
||||
}
|
||||
outs->filename = curlx_dyn_ptr(&fbuffer); /* remember the new one */
|
||||
outs->alloc_filename = TRUE;
|
||||
newfile = curlx_dyn_ptr(&fbuffer); /* remember the new one */
|
||||
if(newfile) {
|
||||
outs->filename = newfile;
|
||||
outs->alloc_filename = TRUE;
|
||||
}
|
||||
}
|
||||
/* An else statement to not overwrite existing files and not retry with
|
||||
new numbered names (which would cover
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue