From 3e451f840a936a69d85deda18dd579df4fac7ed8 Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Tue, 11 Nov 2014 04:20:43 -0800 Subject: [PATCH] Resolve symlinks when executing buck on unix Summary: If buck is checked out in $HOME/devtools/buck yet run via a symlink in /usr/bin it will not run, since we attempt to resolve "/usr/bin/../programs". Eagerly resolving symlinks before executing resolves this problem. Test Plan: /usr/bin/buck --help --- bin/buck | 11 ++++++++++- bin/buckd | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/buck b/bin/buck index a56c234f29b..775be4a45d0 100755 --- a/bin/buck +++ b/bin/buck @@ -1,2 +1,11 @@ #!/bin/sh -exec python "$(dirname $0)"/../programs/buck.py "$@" + +# Resolve symlinks if necessary, otherwise madness will follow. +# On a GNU system, we could use "-f" to follow all symlinks. BSD based +# systems don't have this flag. *sigh* +BUCK_PATH="`readlink $0`" +if [ -z "$BUCK_PATH" ]; then + BUCK_PATH="$0" +fi + +exec python "$(dirname $BUCK_PATH)/../programs/buck.py" "$@" diff --git a/bin/buckd b/bin/buckd index 3cdf50cd8c4..571639febab 100755 --- a/bin/buckd +++ b/bin/buckd @@ -1,2 +1,8 @@ #!/bin/sh + +BUCK_PATH="`readlink $0`" +if [ -z "$BUCK_PATH" ]; then + BUCK_PATH="$0" +fi + exec python "$(dirname $0)"/../programs/buckd.py "$@"