commit:     f7d4124aa6196fce5dc51e1b5007a16830a622df
Author:     Eli Schwartz <eschwartz <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 17 14:00:38 2025 +0000
Commit:     Eli Schwartz <eschwartz <AT> gentoo <DOT> org>
CommitDate: Thu Jul 17 14:05:09 2025 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=f7d4124a

bootstrap-prefix: fix portability in "cp" usage

This script installs Prefix when you don't yet have it. It shouldn't
assume Gentooisms, such as having GNU coreutils!

`cp -a` is a non-portable extension, which fails on at least some macOS
systems (as reported on IRC for macosx ppc 10.4.11). It is documented by
GNU as being one of several shortcut options with the following
equivalencies:

`-a` ---> `-dR --preserve=all`
`-d` ---> `-P --preserve=links`
`-p` ---> `--preserve=mode,ownership,timestamps`
`--preserve=all` ---> `--preserve=mode,ownership,timestamps,links,context,xattr`

Hence `-a` could equally be `-RpP --preserve=links,context,xattr`

FreeBSD has `-a` too, and documents it as a shortcut for `-RpP`.

We use it twice, once to install a just-compiled executable and once to
bootstrap /usr/share/portage. We have no need for the extra GNU
--preserve's. Moreover, -RpP is all documented in POSIX 2008, so it is
sure to work everywhere -- and we use these options elsewhere in this
script already. ;)

Fixes: 636a653fcc42a974748a26cbf6c999592c762466
Acked-by: Sam James <sam <AT> gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz <AT> gentoo.org>

 scripts/bootstrap-prefix.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/bootstrap-prefix.sh b/scripts/bootstrap-prefix.sh
index 35ab634e48..26f8d242a4 100755
--- a/scripts/bootstrap-prefix.sh
+++ b/scripts/bootstrap-prefix.sh
@@ -1319,7 +1319,7 @@ bootstrap_ldwrapper() {
 
        einfo "Installing ${A%.c}"
        mkdir -p "${ROOT}"/tmp/usr/bin
-       cp -a ldwrapper "${ROOT}"/tmp/usr/bin/ || return 1
+       cp -p ldwrapper "${ROOT}"/tmp/usr/bin/ || return 1
 
        einfo "${A%.c} bootstrapped"
 }
@@ -2308,7 +2308,7 @@ bootstrap_stage3() {
        # to finally overwrite it.
        if [[ ! -d "${ROOT}"/usr/share/portage ]]; then
                mkdir -p "${ROOT}"/usr/share
-               cp -a "${ROOT}"{/tmp,}/usr/share/portage
+               cp -RpP "${ROOT}"{/tmp,}/usr/share/portage
        fi
 
        local -a linker_pkgs compiler_pkgs
@@ -2513,7 +2513,7 @@ bootstrap_stage3() {
                        chmod +x "${ROOT}"/usr/bin/ld
                fi
        fi
-       
+
        # Start using apps from the final destination Prefix
        cat > "${ROOT}"/tmp/etc/env.d/10stage3 <<-EOF
                PATH="${ROOT}/usr/bin:${ROOT}/bin"

Reply via email to