From: Daniel Stenberg Date: Mon, 15 Jan 2024 15:49:20 +0000 (+0100) Subject: tool_operate: make --remove-on-error only remove "real" files X-Git-Tag: curl-8_6_0~79 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae9f01f336193047e4d370a18141ec7408f99c0b;p=thirdparty%2Fcurl.git tool_operate: make --remove-on-error only remove "real" files Reported-by: Harry Sintonen Assisted-by: Dan Fandrich Closes #12710 --- diff --git a/docs/cmdline-opts/remove-on-error.d b/docs/cmdline-opts/remove-on-error.d index 50b7b1b65c..2b498bc9ec 100644 --- a/docs/cmdline-opts/remove-on-error.d +++ b/docs/cmdline-opts/remove-on-error.d @@ -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. diff --git a/src/tool_operate.c b/src/tool_operate.c index 1ffd6730ec..ba811d7733 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -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); } }