tool_operate: make --remove-on-error only remove "real" files

Reported-by: Harry Sintonen
Assisted-by: Dan Fandrich

Closes #12710
This commit is contained in:
Daniel Stenberg 2024-01-15 16:49:20 +01:00
parent c5801a28c5
commit ae9f01f336
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 12 additions and 3 deletions

View File

@ -12,4 +12,4 @@ When curl returns an error when told to save output in a local file, this
option removes that saved file before exiting. This prevents curl from
leaving a partial file in the case of an error during transfer.
If the output is not a file, this option has no effect.
If the output is not a regular file, this option has no effect.

View File

@ -637,8 +637,17 @@ noretry:
errorf(config->global, "curl: (%d) Failed writing body", result);
}
if(result && config->rm_partial) {
notef(global, "Removing output file: %s", outs->filename);
unlink(outs->filename);
struct_stat st;
if(!stat(outs->filename, &st) &&
S_ISREG(st.st_mode)) {
if(!unlink(outs->filename))
notef(global, "Removed output file: %s", outs->filename);
else
warnf(global, "Failed removing: %s", outs->filename);
}
else
warnf(global, "Skipping removal; not a regular file: %s",
outs->filename);
}
}