flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject flink git commit: [scripts] resolve base path of symlinked executable
Date Wed, 26 Aug 2015 15:38:41 GMT
Repository: flink
Updated Branches:
  refs/heads/release-0.9 5869bf98b -> 0fe0155da


[scripts] resolve base path of symlinked executable

- also adapt config.sh to use the same cross-platform compatible mechanism


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/0fe0155d
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/0fe0155d
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/0fe0155d

Branch: refs/heads/release-0.9
Commit: 0fe0155da5bc74dad7ea70121c99e185b4611800
Parents: 5869bf9
Author: Maximilian Michels <mxm@apache.org>
Authored: Mon Aug 24 14:40:47 2015 +0200
Committer: Ufuk Celebi <uce@apache.org>
Committed: Wed Aug 26 17:38:17 2015 +0200

----------------------------------------------------------------------
 flink-dist/src/main/flink-bin/bin/config.sh | 34 +++++++++++++-----------
 flink-dist/src/main/flink-bin/bin/flink     | 20 ++++++++++++--
 2 files changed, 36 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/0fe0155d/flink-dist/src/main/flink-bin/bin/config.sh
----------------------------------------------------------------------
diff --git a/flink-dist/src/main/flink-bin/bin/config.sh b/flink-dist/src/main/flink-bin/bin/config.sh
index 2c63cb8..90a0a1e 100755
--- a/flink-dist/src/main/flink-bin/bin/config.sh
+++ b/flink-dist/src/main/flink-bin/bin/config.sh
@@ -99,26 +99,28 @@ KEY_ENV_SSH_OPTS="env.ssh.opts"
 # PATHS AND CONFIG
 ########################################################################################################################
 
-# Resolve links
-this="$0"
-while [ -h "$this" ]; do
-  ls=`ls -ld "$this"`
-  link=`expr "$ls" : '.*-> \(.*\)$'`
-  if expr "$link" : '.*/.*' > /dev/null; then
-    this="$link"
-  else
-    this=`dirname "$this"`/"$link"
-  fi
+target="$0"
+# For the case, the executable has been directly symlinked, figure out
+# the correct bin path by following its symlink up to an upper bound.
+# Note: we can't use the readlink utility here if we want to be POSIX
+# compatible.
+iteration=0
+while [ -L "$target" ]; do
+    if [ "$iteration" -gt 100 ]; then
+        echo "Cannot resolve path: You have a cyclic symlink in $target."
+        break
+    fi
+    ls=`ls -ld -- "$target"`
+    target=`expr "$ls" : '.* -> \(.*\)$'`
+    iteration=$((iteration + 1))
 done
 
-# Convert relative path to absolute path
-bin=`dirname "$this"`
-script=`basename "$this"`
-bin=`cd "$bin"; pwd`
-this="$bin/$script"
+# Convert relative path to absolute path and resolve directory symlinks
+bin=`dirname "$target"`
+SYMLINK_RESOLVED_BIN=`cd "$bin"; pwd -P`
 
 # Define the main directory of the flink installation
-FLINK_ROOT_DIR=`dirname "$this"`/..
+FLINK_ROOT_DIR=`dirname "$SYMLINK_RESOLVED_BIN"`
 FLINK_LIB_DIR=$FLINK_ROOT_DIR/lib
 
 # These need to be mangled because they are directly passed to java.

http://git-wip-us.apache.org/repos/asf/flink/blob/0fe0155d/flink-dist/src/main/flink-bin/bin/flink
----------------------------------------------------------------------
diff --git a/flink-dist/src/main/flink-bin/bin/flink b/flink-dist/src/main/flink-bin/bin/flink
index eb8bca0..7074434 100644
--- a/flink-dist/src/main/flink-bin/bin/flink
+++ b/flink-dist/src/main/flink-bin/bin/flink
@@ -17,8 +17,24 @@
 # limitations under the License.
 ################################################################################
 
-bin=`dirname "$0"`
-bin=`cd "$bin"; pwd`
+target="$0"
+# For the case, the executable has been directly symlinked, figure out
+# the correct bin path by following its symlink up to an upper bound.
+# Note: we can't use the readlink utility here if we want to be POSIX
+# compatible.
+iteration=0
+while [ -L "$target" ]; do
+    if [ "$iteration" -gt 100 ]; then
+        echo "Cannot resolve path: You have a cyclic symlink in $target."
+        break
+    fi
+    ls=`ls -ld -- "$target"`
+    target=`expr "$ls" : '.* -> \(.*\)$'`
+    iteration=$((iteration + 1))
+done
+
+# Convert relative path to absolute path
+bin=`dirname "$target"`
 
 # get flink config
 . "$bin"/config.sh


Mime
View raw message