#!/usr/bin/env bash
# Copyright 1999-2024 Gentoo Authors
# 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
	ED=${D}
fi

args=()
got_owner=
for arg; do
	if [[ ${arg} == -* ]]; then
		args+=( "${arg}" )
	elif [[ ! ${got_owner} ]]; then
		# the first non-option is the owner and must not be prefixed
		got_owner=1
		args+=( "${arg}" )
	else
		args+=( "${ED%/}/${arg#/}" )
	fi
done

chown "${args[@]}"
ret=$?

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