]> 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)
committerBruno Haible <bruno@clisp.org>
Thu, 13 Jun 2024 15:05:36 +0000 (17:05 +0200)
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 4104be72a93a4bcf446629ec6d4cdd4c5ef1031e..d870fdb1487fed886cf5f9b7aa2beed086c67efc 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  Collin Funk  <collin.funk1@gmail.com>
 
        mktempd: Invoke mktemp portably.
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 4689b6b758c27009848ef51bf7fe01db95daa205..6effae27c7a4d4e7099844c7ad923e359777d65c 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 &&