#! /bin/bash

# Removes all files under ${dir} that are identical to the
# corresponding files in ${ref}

dir="$1"; shift
ref="$1"; shift

files=( `find_identical_files.sh ${dir} ${ref}` )

if [[ ${#files[@]} -gt 0 ]]; then
  echo "removing the files in ${dir} that are identical to those in ${ref}" 1>&2
  ls -l "${files[@]}"
  ans="`ask_for_yes_or_no.sh`"
  if [[ "${ans}" != "yes" ]]; then
    echo "** you said '${ans}' - aborted." 1>&2
    exit 1
  fi

  rm -fv "${files[@]}"
else
  echo "no identical files found in ${dir}" 1>&2
fi
