From 910d4bae24b6d399253985740cbd6b63823f58f5 Mon Sep 17 00:00:00 2001 From: "J. Lewis Muir" Date: Mon, 20 Jul 2015 15:10:49 -0500 Subject: [PATCH] pkgtools/pbulk: delete xcrun cache file before unprivileged su On OS X, before running certain phases of a package build as the unprivileged user via su, delete the xcrun cache file of the privileged user to avoid "permission denied" errors in the package build logs when the unprivileged xcrun program tries to overwrite the existing cache file of the privileged user. This is needed because, on OS X Yosemite with Command Line Tools (10.10) for Xcode 6.4, the xcrun program creates an xcrun_db cache file. This cache file will be created when run as the privileged user. Unfortunately, when xcrun is run as the unprivileged user via su, it will try to overwrite the cache file of the privileged user and will fail because it does not have the needed permissions. This results in the configure and build logs being littered with messages like the following (the program name, "gm4", will vary): gm4: error: couldn't replace cache file '/var/tmp/xcrun_db' with newly written file '/var/tmp/xcrun_db-QqnQCjPl' (errno=Permission denied) --- pkgtools/pbulk/files/pbulk/scripts/pkg-build | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pkgtools/pbulk/files/pbulk/scripts/pkg-build b/pkgtools/pbulk/files/pbulk/scripts/pkg-build index 5348c07dec3b2..150245d025e9f 100755 --- a/pkgtools/pbulk/files/pbulk/scripts/pkg-build +++ b/pkgtools/pbulk/files/pbulk/scripts/pkg-build @@ -65,8 +65,33 @@ cleanup() { exit 1 } +delete_xcrun_cache() { + local xcrun_bin xcrun_db_tmp + if [ -z ${xcrun_db+x} ]; then + xcrun_db='' + xcrun_bin=`which xcrun` + [ $? -eq 0 ] || return + [ -n "$xcrun_bin" ] || return + xcrun_db_tmp=`{ "$xcrun_bin" -v true 2>&1; } | \ + grep ' xcrun_db = .*' | head -n 1` + xcrun_db_tmp=${xcrun_db_tmp#*"'"} + xcrun_db_tmp=${xcrun_db_tmp%"'"} + [ "X${xcrun_db_tmp##*/}" = Xxcrun_db ] || return + xcrun_db="$xcrun_db_tmp" + fi + [ -n "$xcrun_db" ] && rm -f "$xcrun_db" +} + +pre_run_su() { + # On OS X, if the privileged user's xcrun cache file exists, delete + # it because the xcrun invoked as the unprivileged user via su may + # try to replace it and fail because it does not have appropriate + # permissions. + delete_xcrun_cache +} + run_direct() { "$@"; } -run_su() { su ${unprivileged_user} -c '"$@"' make "$@"; } +run_su() { pre_run_su; su ${unprivileged_user} -c '"$@"' make "$@"; } run_make() { local run_cmd