sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-2531: readlink -f not supported on OS X
Date Fri, 28 Aug 2015 09:20:59 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk de6fa8279 -> 03ed21b4f


SQOOP-2531: readlink -f not supported on OS X

(Stuart Williams via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/03ed21b4
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/03ed21b4
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/03ed21b4

Branch: refs/heads/trunk
Commit: 03ed21b4f1958a4aeba33ace2a3f06ac34626f9d
Parents: de6fa82
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Fri Aug 28 11:19:59 2015 +0200
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Fri Aug 28 11:19:59 2015 +0200

----------------------------------------------------------------------
 src/scripts/tool-script.sh.template | 76 +++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/03ed21b4/src/scripts/tool-script.sh.template
----------------------------------------------------------------------
diff --git a/src/scripts/tool-script.sh.template b/src/scripts/tool-script.sh.template
index 56b5a1a..94ac915 100644
--- a/src/scripts/tool-script.sh.template
+++ b/src/scripts/tool-script.sh.template
@@ -19,7 +19,81 @@
 # specific language governing permissions and limitations
 # under the License.
 
-prgm=`readlink -f $0`
+follow_one() {
+  # Resolve symlinks and relative path components along a path.  This requires
+  # its argument to be an absolute path.  This does not recursively re-resolve
+  # symlinks; if that is required, use the 'follow' method.
+
+  target=$1
+  OIFS=$IFS
+  IFS='/'
+
+  # Taking each dir component along the way, build up a new target directory,
+  # resolving '.', '..', and symlinks.
+  newtarget=''
+  for part in ${target}; do
+    if [ -z "${part}" ]; then
+      continue # Empty dir part. 'foo//bar'
+    elif [ "." == "${part}" ]; then
+      continue # Nothing special to do for '.'
+    elif  [ ".." == "${part}" ]; then
+      IFS=$OIFS
+      newtarget=`dirname ${newtarget}` # pop a component.
+    elif [ -h "${newtarget}/${part}" ]; then
+      IFS=$OIFS
+      link=`readlink ${newtarget}/${part}`
+      # links can be relative or absolute. Relative ones get appended to
+      # newtarget; absolute ones replace it.
+      if [ "${link:0:1}" != "/"  ]; then
+        newtarget="${newtarget}/${link}" # relative
+      else
+        newtarget="${link}" # absolute
+      fi
+    else # Regular file component.
+      newtarget="${newtarget}/${part}"
+    fi
+    IFS='/'
+  done
+
+  IFS=$OIFS
+  echo $newtarget
+}
+
+follow() {
+  # Portable 'readlink -f' function to follow a file's links to the final
+  # target.  Calls follow_one recursively til we're finished tracing symlinks.
+
+  target=$1
+  depth=$2
+
+  if [ -z "$depth" ]; then
+    depth=0
+  elif [ "$depth" == "1000" ]; then
+    # Don't recurse indefinitely; we've probably hit a symlink cycle.
+    # Just bail out here.
+    echo $target
+    return 1
+  fi
+
+  # Canonicalize the target to be an absolute path.
+  targetdir=`dirname ${target}`
+  targetdir=`cd ${targetdir} && pwd`
+  target=${targetdir}/`basename ${target}`
+
+  # Use follow_one to resolve links. Test that we get the same result twice,
+  # to terminate iteration.
+  first=`follow_one ${target}`
+  second=`follow_one ${first}`
+  if [ "${first}" == "${second}" ]; then
+    # We're done.
+    echo "${second}"
+  else
+    # Need to continue resolving links.
+    echo `follow ${second} $(( $depth + 1 ))`
+  fi
+}
+
+prgm=`follow $0`
 bin=`dirname ${prgm}`
 bin=`cd ${bin} && pwd`
 


Mime
View raw message