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.
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);
}
}