]> Savannah Git Hosting - gnulib.git/commitdiff
mktempd: use GNU-style -t if available
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Jun 2024 22:09:55 +0000 (15:09 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Jun 2024 22:11:27 +0000 (15:11 -0700)
This better satisfies Jim Meyering’s point in:
https://lists.gnu.org/archive/html/bug-gnulib/2016-03/msg00074.html
that it’s more useful when each temporary test directory name
includes the corresponding test’s name.
* build-aux/mktempd: Try mktemp -t only with GNU syntax, so that
NetBSD mktemp fails.  Also, reject templates beginning with "-" so
that they are not treated as options.
* tests/init.sh (mktempd_): Likewise.

ChangeLog
build-aux/mktempd
tests/init.sh

index caef27ff722b66b7ac3a472cf5b34e62035777d2..ec9505fc701825b3e82f6e65e5f4acee7e154dea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-06-11  Paul Eggert  <eggert@cs.ucla.edu>
+
+       mktempd: use GNU-style -t if available
+       This better satisfies Jim Meyering’s point in:
+       https://lists.gnu.org/archive/html/bug-gnulib/2016-03/msg00074.html
+       that it’s more useful when each temporary test directory name
+       includes the corresponding test’s name.
+       * build-aux/mktempd: Try mktemp -t only with GNU syntax, so that
+       NetBSD mktemp fails.  Also, reject templates beginning with "-" so
+       that they are not treated as options.
+       * tests/init.sh (mktempd_): Likewise.
+
 2024-06-11  Bruno Haible  <bruno@clisp.org>
 
        parse-datetime: Add support for VPATH builds with OpenBSD 'make'.
index 542a4016fe657ff952d8a336d25ecf391a8cf6c7..cc4824a3ebda59a9a22b31f95a5af391af1f64e0 100755 (executable)
@@ -84,14 +84,17 @@ mktempd()
   esac
 
   case $template in
+  -*) die "invalid template: $template (cannot start with '-')";;
   *XXXX) ;;
   *) die "invalid template: $template (must have a suffix of at least 4 X's)";;
   esac
 
   fail=0
 
-  # First, try to use mktemp.
-  d=`env -u TMPDIR mktemp -d -p "$destdir" "$template" 2>/dev/null` \
+  # First, try GNU mktemp, where -t has no option-argument.
+  # Put -t last, as GNU mktemp allows, so that the incompatible NetBSD mktemp
+  # (where -t has an option-argument) fails instead of creating a junk dir.
+  d=`env -u TMPDIR mktemp -d -p "$destdir" "$template" -t 2>/dev/null` \
     || fail=1
 
   # The resulting name must be in the specified directory.
index 2724f5ab6724d04b146572909b26a555c1363e5a..237db02fb063e38d10ae32ff872019f764201205 100644 (file)
@@ -338,13 +338,17 @@ mktempd_ ()
   esac
 
   case $template_ in
+  -*) fail _ \
+       "invalid template: $template_ (must not begin with '-')";;
   *XXXX) ;;
   *) fail_ \
        "invalid template: $template_ (must have a suffix of at least 4 X's)";;
   esac
 
-  # First, try to use mktemp.
-  d=`unset TMPDIR; { mktemp -d -p "$destdir_" "$template_"; } 2>/dev/null` &&
+  # First, try GNU mktemp, where -t has no option-argument.
+  # Put -t last, as GNU mktemp allows, so that the incompatible NetBSD mktemp
+  # (where -t has an option-argument) fails instead of creating a junk dir.
+  d=`unset TMPDIR; { mktemp -d -p "$destdir_" "$template_" -t; } 2>/dev/null` &&
 
   # The resulting name must be in the specified directory.
   case $d in "$destdir_slash_"*) :;; *) false;; esac &&