]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Use mktemp, not mkdtemp, to create test directories.
authorJim Meyering <meyering@redhat.com>
Thu, 1 Nov 2007 17:58:17 +0000 (18:58 +0100)
committerJim Meyering <meyering@redhat.com>
Thu, 1 Nov 2007 19:13:11 +0000 (20:13 +0100)
* tests/test-lib.sh: Use the mktemp binary we've just built,
not the mkdtemp script.
* tests/mkdtemp: Remove file.
* tests/Makefile.am (EXTRA_DIST): Remove mkdtemp.

ChangeLog
tests/Makefile.am
tests/mkdtemp [deleted file]
tests/test-lib.sh

index 2344f28dde304a1880523dd9f1b8fe9de605c69d..cfb5c79cbab26f8573307f60b24e17a8d1f1db5c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2007-11-01  Jim Meyering  <meyering@redhat.com>
 
+       Use mktemp, not mkdtemp, to create test directories.
+       * tests/test-lib.sh: Use the mktemp binary we've just built,
+       not the mkdtemp script.
+       * tests/mkdtemp: Remove file.
+       * tests/Makefile.am (EXTRA_DIST): Remove mkdtemp.
+
        Adjust a seq subtest not to depend on the vagaries of floating point.
        * tests/misc/seq (float-3): Use 10.94 as the endpoint, not 10.95,
        since 10.95 was precisely in the middle of the interval, and with
index cc67c2ad754f7b5f8ca4b1364d252d0a6d244501..f7c837fae164594a29e9b8bd6582ab0221ce0acf 100644 (file)
@@ -20,7 +20,6 @@ EXTRA_DIST =          \
   input-tty            \
   lang-default         \
   mk-script            \
-  mkdtemp              \
   other-fs-tmpdir      \
   priv-check           \
   rwx-to-mode          \
diff --git a/tests/mkdtemp b/tests/mkdtemp
deleted file mode 100755 (executable)
index 48fe054..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/bin/sh
-# Create a temporary directory, sort of like mktemp -d does.
-# Usage: mkdtemp /tmp phoey.XXXXXXXXXX
-
-# First, try to use the mktemp program.
-# Failing that, we'll roll our own mktemp-like function:
-#  - try to get random bytes from /dev/urandom
-#  - failing that, generate output from a combination of quickly-varying
-#      sources and gzip.  Ignore non-varying gzip header, and extract
-#      "random" bits from there.
-#  - given those bits, map to file-name bytes using tr, and try to create
-#      the desired directory.
-#  - make only $MAX_TRIES attempts
-
-ME=$(basename "$0")
-die() { echo >&2 "$ME: $@"; exit 1; }
-
-MAX_TRIES=4
-
-rand_bytes()
-{
-  n=$1
-
-  chars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
-
-  dev_rand=/dev/urandom
-  if test -r "$dev_rand"; then
-    # Note: 256-length($chars) == 194; 3 copies of $chars is 186 + 8 = 194.
-    head -c$n "$dev_rand" | tr -c $chars 01234567$chars$chars$chars
-    return
-  fi
-
-  cmds='date; date +%N; free; who -a; w; ps auxww; ps ef; netstat -n'
-  data=$( (eval "$cmds") 2>&1 | gzip )
-
-  n_plus_50=$(expr $n + 50)
-
-  # Ensure that $data has length at least 50+$n
-  while :; do
-    len=$(echo "$data"|wc -c)
-    test $n_plus_50 -le $len && break;
-    data=$( (echo "$data"; eval "$cmds") 2>&1 | gzip )
-  done
-
-  echo "$data" \
-    | dd bs=1 skip=50 count=$n 2>/dev/null \
-    | tr -c $chars 01234567$chars$chars$chars
-}
-
-mkdtemp()
-{
-  case $# in
-  2);;
-  *) die "Usage: $ME DIR TEMPLATE";;
-  esac
-
-  destdir=$1
-  template=$2
-
-  case $template in
-  *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 -t -p "$destdir" "$template" 2>/dev/null) \
-    || fail=1
-
-  # The resulting name must be in the specified directory.
-  case $d in "$destdir"*);; *) fail=1;; esac
-
-  # It must have created the directory.
-  test -d "$d" || fail=1
-
-  # It must have 0700 permissions.
-  perms=$(ls -dgo "$d" 2>/dev/null) || fail=1
-  case $perms in drwx------*) ;; *) fail=1;; esac
-
-  test $fail = 0 && {
-    echo "$d"
-    return
-  }
-
-  # If we reach this point, we'll have to create a directory manually.
-
-  # Get a copy of the template without its suffix of X's.
-  base_template=$(echo "$template"|sed 's/XX*$//')
-
-  # Calculate how many X's we've just removed.
-  nx=$(expr length "$template" - length "$base_template")
-
-  err=
-  i=1
-  while :; do
-    X=$(rand_bytes $nx)
-    candidate_dir="$destdir/$base_template$X"
-    err=$(mkdir -m 0700 "$candidate_dir" 2>&1) \
-      && { echo "$candidate_dir"; return; }
-    test $MAX_TRIES -le $i && break;
-    i=$(expr $i + 1)
-  done
-  die "$err"
-}
-
-mkdtemp "$@"
index 495fd2a05793c867eb771e936531bd904d10249b..b90f98ff7610e3e7635b2ea7cf8be40f642552e6 100644 (file)
@@ -80,7 +80,7 @@ this_test=$(this_test_)
 # a partition, or to undo any other global state changes.
 cleanup_() { :; }
 
-t_=$($abs_top_srcdir/tests/mkdtemp $test_dir_ cu-$this_test.XXXXXXXXXX) \
+t_=$($abs_top_builddir/src/mktemp -d --tmp="$test_dir_" cu-$this_test.XXXXXXXXXX)\
     || error_ "failed to create temporary directory in $test_dir_"
 
 # Run each test from within a temporary sub-directory named after the