mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 06:51:49 +08:00
Use portable shell code to follow symlinks.
From: Aaron Kimball <aaron@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149911 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
74d034cf36
commit
7b37789b4f
@ -18,9 +18,12 @@
|
|||||||
# This is sourced in by bin/sqoop to set environment variables prior to
|
# This is sourced in by bin/sqoop to set environment variables prior to
|
||||||
# invoking Hadoop.
|
# invoking Hadoop.
|
||||||
|
|
||||||
prgm=`readlink -f $0`
|
bin="$1"
|
||||||
bin=`dirname ${prgm}`
|
|
||||||
bin=`cd ${bin} && pwd`
|
if [ -z "${bin}" ]; then
|
||||||
|
bin=`dirname $0`
|
||||||
|
bin=`cd ${bin} && pwd`
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$SQOOP_HOME" ]; then
|
if [ -z "$SQOOP_HOME" ]; then
|
||||||
export SQOOP_HOME=${bin}/..
|
export SQOOP_HOME=${bin}/..
|
||||||
|
79
bin/sqoop
79
bin/sqoop
@ -15,10 +15,85 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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=`dirname ${prgm}`
|
||||||
bin=`cd ${bin} && pwd`
|
bin=`cd ${bin} && pwd`
|
||||||
|
|
||||||
source ${bin}/configure-sqoop
|
source ${bin}/configure-sqoop "${bin}"
|
||||||
${HADOOP_HOME}/bin/hadoop jar ${SQOOP_JAR} \
|
${HADOOP_HOME}/bin/hadoop jar ${SQOOP_JAR} \
|
||||||
com.cloudera.sqoop.Sqoop "$@"
|
com.cloudera.sqoop.Sqoop "$@"
|
||||||
|
@ -30,7 +30,7 @@ bin=`cd ${bin} && pwd`
|
|||||||
SQOOP_HOME="${bin}/../../"
|
SQOOP_HOME="${bin}/../../"
|
||||||
|
|
||||||
# Set up environment and classpath
|
# Set up environment and classpath
|
||||||
source ${SQOOP_HOME}/bin/configure-sqoop
|
source ${SQOOP_HOME}/bin/configure-sqoop "${bin}"
|
||||||
|
|
||||||
PERFTEST_CLASSES=${SQOOP_HOME}/build/perftest/classes
|
PERFTEST_CLASSES=${SQOOP_HOME}/build/perftest/classes
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user