Repository: incubator-predictionio
Updated Branches:
  refs/heads/develop 54301370e -> 84d683f74


[PIO-46] Fix readlink with -f option not working on BSD based systems

Closes #319


Project: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/commit/84d683f7
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/tree/84d683f7
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-predictionio/diff/84d683f7

Branch: refs/heads/develop
Commit: 84d683f745591a5ab4fd205b2bbff585da132921
Parents: 5430137
Author: takahiro-hagino <[email protected]>
Authored: Fri Dec 16 10:09:38 2016 -0800
Committer: Donald Szeto <[email protected]>
Committed: Fri Dec 16 10:09:38 2016 -0800

----------------------------------------------------------------------
 bin/pio | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/84d683f7/bin/pio
----------------------------------------------------------------------
diff --git a/bin/pio b/bin/pio
index 1f6e0ed..fca48f6 100755
--- a/bin/pio
+++ b/bin/pio
@@ -32,7 +32,26 @@ search() {
   echo ${i}
 }
 
-export PIO_HOME="$(cd $(dirname $(readlink -f $0))/..; pwd)"
+PIO_FILE=$(readlink -f $0 2>/dev/null)
+if [ $? = 0 ] ; then 
+  export PIO_HOME="$(cd $(dirname $PIO_FILE)/..; pwd)"
+else
+  CURRENT_DIR=`pwd`
+  TARGET_FILE="$0"
+  cd "$(dirname "$TARGET_FILE")"
+  TARGET_FILE=$(basename "$TARGET_FILE")
+
+  while [ -L "$TARGET_FILE" ]
+  do
+    TARGET_FILE=$(readlink "$TARGET_FILE")
+    cd "$(dirname "$TARGET_FILE")"
+    TARGET_FILE=$(basename "$TARGET_FILE")
+  done
+
+  export PIO_HOME="$(cd $(dirname "$TARGET_FILE")/..; pwd -P)"
+  cd "$CURRENT_DIR"
+fi
+
 
 export PIO_CONF_DIR="${PIO_HOME}/conf"
 

Reply via email to