[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Thu Jun 5 12:27:13 UTC 2008


 bootstrap.conf    |    1 
 tests/Makefile.am |    2 -
 tests/mkdtemp     |  107 ------------------------------------------------------
 tests/test-lib.sh |    2 -
 4 files changed, 3 insertions(+), 109 deletions(-)

New commits:
commit ff44d5b2392c41a67ee1f628baa1813ccbfb6981
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu Jun 5 13:55:30 2008 +0200

    use gnulib's mktempd module/script
    
    * bootstrap.conf (gnulib_modules): Add mktempd.
    * tests/test-lib.sh: Use build-aux/mktempd, not mkdtemp.
    * tests/mkdtemp: Remove file.
    * tests/Makefile.am (EXTRA_DIST): Remove mkdtemp.

diff --git a/bootstrap.conf b/bootstrap.conf
index c54fcea..f7bd5e4 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -48,6 +48,7 @@ gnulib_modules="
 	lib-ignore
 	long-options
 	malloc
+	mktempd
 	realloc
 	rpmatch
 	progname
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e41b5ae..d6b2731 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,7 @@ TESTS = \
   t5000-tags.sh
 
 EXTRA_DIST = \
-  $(TESTS) test-lib.sh mkdtemp
+  $(TESTS) test-lib.sh
 
 CLEANFILES = init.sh
 all: init.sh
diff --git a/tests/mkdtemp b/tests/mkdtemp
deleted file mode 100755
index 48fe054..0000000
--- a/tests/mkdtemp
+++ /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 "$@"
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 9ce10e2..77a9ab9 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -282,7 +282,7 @@ do
 	esac
 done
 
-t0=$($abs_top_srcdir/tests/mkdtemp $test_dir_ parted-$this_test.XXXXXXXXXX) \
+t0=$($abs_top_srcdir/build-aux/mktempd $test_dir_ parted-$this_test.XXXXXXXXXX) \
     || error "failed to create temporary directory in $test_dir_"
 
 # Run each test from within a temporary sub-directory named after the



More information about the Parted-commits mailing list