]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: make --remove-on-error only remove "real" files
authorDaniel Stenberg <daniel@haxx.se>
Mon, 15 Jan 2024 15:49:20 +0000 (16:49 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 16 Jan 2024 09:57:12 +0000 (10:57 +0100)
Reported-by: Harry Sintonen
Assisted-by: Dan Fandrich
Closes #12710

docs/cmdline-opts/remove-on-error.d
src/tool_operate.c

index 50b7b1b65cf31ab8f5eca798ad8b694422b24e55..2b498bc9ec55884917e7a54b2db2a2000b6a40e1 100644 (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.
index 1ffd6730ec824dcbb22007cf91ae68fb7adbbd8d..ba811d77331483c2b7c70d1bdb105e401c77ddd3 100644 (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);
     }
   }