diff options
author | Andrew Hsieh <andrewhsieh@google.com> | 2014-11-17 10:51:34 +0800 |
---|---|---|
committer | Andrew Hsieh <andrewhsieh@google.com> | 2014-12-05 15:17:50 +0800 |
commit | 083bc972881f7f056fb4cbd167e31679ae91bbe0 (patch) | |
tree | eacf0a52d02e2d7017369d10eb870f0e97b1a6bb /build | |
parent | 925de2c1df21949ac5aaf79532afbb316461754e (diff) | |
download | ndk-083bc972881f7f056fb4cbd167e31679ae91bbe0.tar.gz |
Refactor dereferencing windows symlink
Move to a new function dereference_symlink
Change-Id: Id775d345639ecdf79ea5d3db07d1b3012fb26068
Diffstat (limited to 'build')
-rw-r--r-- | build/tools/ndk-common.sh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/build/tools/ndk-common.sh b/build/tools/ndk-common.sh index ba38e3ff0..f086628ac 100644 --- a/build/tools/ndk-common.sh +++ b/build/tools/ndk-common.sh @@ -945,3 +945,36 @@ rotate_log () ver=$prev done } + +# Dereference symlink +# $1+: directories +dereference_symlink () +{ + local DIRECTORY SYMLINKS DIR FILE LINK + for DIRECTORY in "$@"; do + if [ -d "$DIRECTORY" ]; then + while true; do + # Find all symlinks in this directory. + SYMLINKS=`find $DIRECTORY -type l` + if [ -z "$SYMLINKS" ]; then + break; + fi + # Iterate symlinks + for SYMLINK in $SYMLINKS; do + if [ -L "$SYMLINK" ]; then + DIR=`dirname "$SYMLINK"` + FILE=`basename "$SYMLINK"` + # Note that if `readlink $FILE` is also a link, we want to deal + # with it in the next iteration. There is potential infinite-loop + # situation for cicular link doesn't exist in our case, though. + (cd "$DIR" && \ + LINK=`readlink "$FILE"` && \ + test ! -L "$LINK" && \ + rm -f "$FILE" && \ + cp -a "$LINK" "$FILE") + fi + done + done + fi + done +} |