#!/usr/bin/env pkgcore-ipc-helper

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

TMP=$(mktemp -d -p "${T}" ".${HELPER_NAME}_XXXXXX")
trap 'rm -rf "${TMP}"' EXIT

if ${PKGCORE_NEW_READS_STDIN} && [[ $1 == "-" ]]; then
	if [[ -t 0 ]]; then
		__helper_exit 1 "no input data available, stdin is a tty"
	fi
	check_command_or_stop cat > "${TMP}/$2"
else
	check_command_or_stop cp -- "$1" "${TMP}/$2"
fi

set -- "${TMP}/$2"
IPC_CMD=do${HELPER_NAME#new}
