]> git.seodisparate.com - SimpleArchiver/commitdiff
Do not create archive file on failure
authorStephen Seo <seo.disparate@gmail.com>
Thu, 18 Jul 2024 13:09:03 +0000 (22:09 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 18 Jul 2024 13:09:03 +0000 (22:09 +0900)
src/main.c

index c89443d7ee067cb142a93a789ecd24466c8d11cc..a47804480d2934b2f509babc38c39b499c5a9a62 100644 (file)
 
 #include <stdio.h>
 
+#include "platforms.h"
+#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \
+    SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC ||          \
+    SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX
+#include <unistd.h>
+#endif
+
 #include "archiver.h"
 #include "parser.h"
 
@@ -78,6 +85,13 @@ int main(int argc, const char **argv) {
       fprintf(stderr, "  %s\n", error_str);
     }
     fclose(file);
+#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \
+    SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC ||          \
+    SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX
+    if (ret != SDAS_SUCCESS) {
+      unlink(parsed.filename);
+    }
+#endif
   } else if ((parsed.flags & 3) == 2) {
     FILE *file = fopen(parsed.filename, "rb");
     if (!file) {