#!/bin/sh

# Like rm -rf, but the actual space is on the scratch disk.

SCRATCH=/scratch/$USER

deldir () {
if mv $1 $1.junk
then
  rm -rf $1.junk  &
else
  rm -rf $1
fi
}

pwd=''
for d in $*
do
  if test -h "$d"
  then
    if test /${d#/} = $d
    then da="$d"
    else
      if test -z "$pwd"
      then pwd=$(pwd)
      fi
      da="$pwd/$d"
    fi
    deldir "$SCRATCH$da"
  elif test -d "$d"
  then
    deldir "$d"
  fi
done
rm -rf "$@"
wait
