]> git.seodisparate.com - SimpleArchiver/commitdiff
Add "--force-tmpfile"
authorStephen Seo <seo.disparate@gmail.com>
Thu, 27 Feb 2025 01:31:58 +0000 (10:31 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 27 Feb 2025 01:35:50 +0000 (10:35 +0900)
"--force-tmpfile" forces the use of "tmpfile()" instead of a file
created in the default directory for temporary files (which is currently
the same directory as the currently created archive) when using
compression.

Note that this option is mutually exclusive with "--temp-files-dir".

Changelog.md
README.md
src/helpers.c
src/main.c
src/parser.c
src/parser.h

index 5ca71fed89d729176dfc438e7b8c21387d10386c..2758b1e2aaebc8dd191eede9e16380fe39eaa142 100644 (file)
@@ -10,6 +10,10 @@ Some minor fixes.
 Changed behavior of permissions for temp-file (created during compression) to
 be more strict. This may not be important to most end-users.
 
+Added `--force-tmpfile`, which acts like `--temp-files-dir <dir>` but forces the
+use of `tmpdir()` instead of forcing the temporary file's directory.  
+Note that these two flags are mutually exclusive.
+
 ## Version 1.17
 
 Fix `--whitelist-begins-with <text>` and `--whitelist-ends-with <text>`.
index a8bc6a95b429c5a6e51e48c0fa556dd443c37840..0e7c2a19957d69363022af6ee2f7a97549651fa2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -31,7 +31,8 @@ API calls.
     --no-abs-symlink : do not store absolute paths for symlinks
     --preserve-symlinks : preserve the symlink's path on archive creation instead of deriving abs/relative paths, ignores "--no-abs-symlink" (It is not recommended to use this option, as absolute-path-symlinks may be clobbered on extraction)
     --no-safe-links : keep symlinks that link to outside archive contents
-    --temp-files-dir <dir> : where to store temporary files created when compressing (defaults to same directory as output file)
+    --temp-files-dir <dir> : where to store temporary files created when compressing (defaults to same directory as output file) (this is mutually exclusive with "--force-tmpfile")
+    --force-tmpfile : Force the use of "tmpfile()" during compression (this is mutually exclusive with "--temp-files-dir")
     --write-version <version> : Force write version file format (default 4)
     --chunk-min-size <bytes> : minimum chunk size (default 4194304 or 4MiB) when using chunks (file formats v. 1 and up)
     --no-pre-sort-files : do NOT pre-sort files by size (by default enabled so that the first file is the largest)
index e4b5921a9195a2bafc1e8301bfccbcd9a4f85ef8..66cccf1cc1f67ace8c2782541833471f81ccbb0f 100644 (file)
@@ -852,6 +852,10 @@ uint_fast8_t simple_archiver_helper_string_allowed_lists(
 
 FILE *simple_archiver_helper_temp_dir(const SDArchiverParsed *parsed,
                                       char **out_temp_filename) {
+  if (parsed->flags & 0x40000) {
+    return tmpfile();
+  }
+
   __attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))
   char *real_path_to_filename = parsed->temp_dir
     ? strdup(parsed->temp_dir)
index 5f3c137a382c87a0baafafc6a9c6d7ce26e16547..d68ca0e862f594799c133fd1aa9f70aee50a2998 100644 (file)
@@ -59,6 +59,15 @@ int main(int argc, const char **argv) {
     return 6;
   }
 
+  if (parsed.temp_dir && (parsed.flags & 0x40000)) {
+    fprintf(stderr,
+            "ERROR: \"--temp-files-dir\" and \"--force-tmpfile\" is mutually "
+            "exclusive!\n");
+    sleep(2);
+    simple_archiver_print_usage();
+    return 9;
+  }
+
   if ((parsed.flags & 0x3) == 0 && (parsed.flags & 0x2000) != 0) {
     fprintf(stderr,
             "WARNING: --force-dir-permissions specified, but has no effect "
index f4fcae437505850bbc4dc8c3c0798c10db853861..7cc60c61b93832e1fb7f8a9c550534e4f40cfd0a 100644 (file)
@@ -186,7 +186,12 @@ void simple_archiver_print_usage(void) {
           "contents\n");
   fprintf(stderr,
           "--temp-files-dir <dir> : where to store temporary files created "
-          "when compressing (defaults to same directory as output file)\n");
+          "when compressing (defaults to same directory as output file) "
+          "(this is mutually exclusive with \"--force-tmpfile\")\n");
+  fprintf(stderr,
+          "--force-tmpfile : Force the use of \"tmpfile()\" during "
+          "compression (this is mutually exclusive with \"--temp-files-dir\")"
+          "\n");
   fprintf(stderr,
           "--write-version <version> : Force write version file format "
           "(default 4)\n");
@@ -479,6 +484,8 @@ int simple_archiver_parse_args(int argc, const char **argv,
         out->temp_dir = simple_archiver_helper_real_path_to_name(argv[1]);
         --argc;
         ++argv;
+      } else if (strcmp(argv[0], "--force-tmpfile") == 0) {
+        out->flags |= 0x40000;
       } else if (strcmp(argv[0], "--write-version") == 0) {
         if (argc < 2) {
           fprintf(stderr,
index 490c7010cc94cb83cfe2dfebba9877a7e90f4811..29be7f3302bf5dec0417e34463d11453a5b8c470 100644 (file)
@@ -61,6 +61,7 @@ typedef struct SDArchiverParsed {
   /// 0b xxxx xxx1 xxxx xxxx xxxx xxxx - Force set empty directory permissions.
   /// 0b xxxx xx1x xxxx xxxx xxxx xxxx - white/black-list checking is
   ///   case-insensitive.
+  /// 0b xxxx x1xx xxxx xxxx xxxx xxxx - Force use tmpfile.
   uint32_t flags;
   /// Null-terminated string.
   char *filename;