#!/bin/sh set -eu u="Ensure that BUILDDIR is an empty directory. If BUILDDIR does not exist, create it. If BUILDDIR does exist, delete all its contents. To avoid deleting things accidentally, we refuse to delete BUILDDIR unless it contains a file named 'this-is-a-nightly-build-dir'. We place a file by that name in directories we create." eval "$(args wipe-build-tree builddir -- "$@")" if [ -d $builddir ]; then if [ -f $builddir/this-is-a-nightly-build-dir ]; then # Don't delete and re-create the directory; delete its contents. # This way, if $builddir is a symlink (say, to a tree on another # filesystem), we don't break it. rm -rf $builddir/* else echo "error: $builddir does not seem to be a nightly build dir" >&2 exit 1 fi else mkdir $builddir fi touch $builddir/this-is-a-nightly-build-dir