#!/usr/bin/env pkgcore-ebuild-helper
# Copyright: 2012 Brian Harring <ferringb@gmail.com>
# License: GPLv2 or bsd-3

check_args 2

if [[ -z ${T} ]]; then
	__helper_exit 2 "environment issue (ebuild commands somehow filtered the env for ${HELPER_NAME} call)- \${T} was empty"
fi

rm -rf "${T}/$2"

if ${PKGCORE_NEW_READS_STDIN} && [[ $1 == "-" ]]; then
	if [[ -t 0 ]]; then
		die "${HELPER_NAME#new} - $2 cannot be invoked with stdin as a tty"
	fi
	check_command_or_stop cat > "${T}/$2"
else
	check_command_or_stop cp -- "$1" "${T}/$2"
fi
invoke_script "do${HELPER_NAME#new}" "${T}/$2"
rm -f "${T}/$2"
