#!/usr/bin/env bash
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1

if ! ___eapi_has_prefix_variables; then
	EPREFIX= ED=${D}
fi

got_owner=
for arg; do
	[[ ${arg} == -* ]] && continue

	if [[ ! ${got_owner} ]]; then
		got_owner=1
		continue
	fi

	if [[ ${arg} != /* ]]; then
		eqawarn "Relative path passed to '${0##*/}': ${arg}"
		eqawarn "This is unsupported. Please use 'chown' when you need to work on files"
		eqawarn "outside the installation image (\${ED})."
	fi
done


# we can't prefix all arguments because
# chown takes random options
slash="/"
chown "${@/#${slash}/${ED%/}${slash}}"
ret=$?

[[ ${ret} -ne 0 ]] && __helpers_die "${0##*/} failed"
exit ${ret}
