mirror of
https://github.com/curl/curl.git
synced 2026-08-02 02:30:27 +03:00
curl: add --remove-on-error
If a transfer returns an error, using this option makes curl remove the leftover downloded (partial) local file before exiting. Added test 376 to verify Closes #8503
This commit is contained in:
parent
7b0fd39db2
commit
08a96c6e4e
9 changed files with 93 additions and 2 deletions
|
|
@ -294,6 +294,8 @@ struct OperationConfig {
|
|||
struct OperationConfig *prev;
|
||||
struct OperationConfig *next; /* Always last in the struct */
|
||||
struct State state; /* for create_transfer() */
|
||||
bool rm_partial; /* on error, remove partially written output
|
||||
files */
|
||||
};
|
||||
|
||||
struct GlobalConfig {
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ static const struct LongShort aliases[]= {
|
|||
{"fb", "styled-output", ARG_BOOL},
|
||||
{"fc", "mail-rcpt-allowfails", ARG_BOOL},
|
||||
{"fd", "fail-with-body", ARG_BOOL},
|
||||
{"fe", "remove-on-error", ARG_BOOL},
|
||||
{"F", "form", ARG_STRING},
|
||||
{"Fs", "form-string", ARG_STRING},
|
||||
{"g", "globoff", ARG_BOOL},
|
||||
|
|
@ -1830,7 +1831,10 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
|
|||
case 'd': /* --fail-with-body */
|
||||
config->failwithbody = toggle;
|
||||
break;
|
||||
default: /* --fail (hard on errors) */
|
||||
case 'e': /* --remove-on-error */
|
||||
config->rm_partial = toggle;
|
||||
break;
|
||||
default: /* --fail (hard on errors) */
|
||||
config->failonerror = toggle;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -574,6 +574,9 @@ const struct helptxt helptext[] = {
|
|||
{"-R, --remote-time",
|
||||
"Set the remote file's time on the local output",
|
||||
CURLHELP_OUTPUT},
|
||||
{" --remove-on-error",
|
||||
"Remove output file on errors",
|
||||
CURLHELP_CURL},
|
||||
{"-X, --request <method>",
|
||||
"Specify request method to use",
|
||||
CURLHELP_CONNECTION},
|
||||
|
|
|
|||
|
|
@ -595,6 +595,10 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
|
|||
if(global->showerror)
|
||||
fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
|
||||
}
|
||||
if(result && config->rm_partial) {
|
||||
notef(global, "Removing output file: %s", per->outfile);
|
||||
unlink(per->outfile);
|
||||
}
|
||||
}
|
||||
|
||||
/* File time can only be set _after_ the file has been closed */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue