#! /bin/sh
#
#  Script to portably delete the very deeply nested directory trees created
#  by the test scripts.  All of these trees have only one subdir per
#  directory, and all the directory names are of the form tmpdirXXX.
#
#  Virtually all Unix systems are capable of building very deeply nested
#  directory trees, however deleting such trees can be a challenge.  Bugs
#  seen in current systems include "rm -rf" dumping core, "find" dumping
#  core or hanging in an infinite loop, etc.
#
#  The strategy here is simply to remember where we started from, cd
#  down the tree until we get to the bottom, and then cd back up the
#  tree one directory at a time, removing the subdir contents and then
#  the subdir itself.  Finally, cd back to where we started from.

top=`pwd`

while test -d tmpdir???
do
	cd tmpdir???
done

while cd .. && test -d tmpdir???
do
	rm -f tmpdir???/*
	rmdir tmpdir???
done

cd $top
