Skip to content
Snippets Groups Projects
Commit 3e61921f authored by Christian Engwer's avatar Christian Engwer
Browse files

better implementation of canonicalname

[[Imported from SVN: r5179]]
parent cd207d73
No related branches found
No related tags found
No related merge requests found
......@@ -17,23 +17,40 @@ fi
###
canonicalname(){
if test $# -ne 1; then
echo Usage: canonicalname path >&2
return 1
fi
name="$1"
while test -L "$name"; do
if ! test -e "$name"; then
echo $name: file not found >&2
return 1
fi
if newname="`readlink $name`"; then
name="$newname"
else
echo "$(dirname $name)/$(basename $name)"
fi
done
echo $name
if test $# -ne 1; then
echo Usage: canonicalname path >&2
return 1
fi
file="$1"
if test ! -e "$file"; then
echo $file: file not found >&2
return 1
fi
# if this is a symlink, then follow the symlink
if test -L "$file"; then
fdir="`dirname \"$file\"`"
flink="`readlink \"$file\"`"
if test -e "$flink"; then
# these are absolute links, or links in the CWD
canonicalname "$flink"
else
canonicalname "$fdir/$flink"
fi
else
# if this is a file, then remember the filename and
# canonicalize the directory name
if test -f "$file"; then
fdir="`dirname \"$file\"`"
fname="`basename \"$file\"`"
fdir="`canonicalname \"$fdir\"`"
echo "$fdir/$fname"
fi
# if this is a directory, then create an absolute
# directory name and we are done
if test -d "$file"; then
(cd "$file"; pwd)
fi
fi
}
canonicalpath(){
......@@ -41,7 +58,7 @@ canonicalpath(){
echo Usage: canonicalpath path >&2
return 1
fi
(cd $(dirname $(canonicalname $1)) && pwd)
dirname $(canonicalname "$1")
}
if test "x$1" = "x--debug"; then
......
......@@ -10,23 +10,40 @@
set -e
canonicalname(){
if test $# -ne 1; then
echo Usage: canonicalname path >&2
return 1
fi
name="$1"
while test -L "$name"; do
if ! test -e "$name"; then
echo $name: file not found >&2
return 1
fi
if newname="`readlink $name`"; then
name="$newname"
else
echo "$(dirname $name)/$(basename $name)"
fi
done
echo $name
if test $# -ne 1; then
echo Usage: canonicalname path >&2
return 1
fi
file="$1"
if test ! -e "$file"; then
echo $file: file not found >&2
return 1
fi
# if this is a symlink, then follow the symlink
if test -L "$file"; then
fdir="`dirname \"$file\"`"
flink="`readlink \"$file\"`"
if test -e "$flink"; then
# these are absolute links, or links in the CWD
canonicalname "$flink"
else
canonicalname "$fdir/$flink"
fi
else
# if this is a file, then remember the filename and
# canonicalize the directory name
if test -f "$file"; then
fdir="`dirname \"$file\"`"
fname="`basename \"$file\"`"
fdir="`canonicalname \"$fdir\"`"
echo "$fdir/$fname"
fi
# if this is a directory, then create an absolute
# directory name and we are done
if test -d "$file"; then
(cd "$file"; pwd)
fi
fi
}
canonicalpath(){
......@@ -34,7 +51,7 @@ canonicalpath(){
echo Usage: canonicalpath path >&2
return 1
fi
(cd $(dirname $(canonicalname $1)) && pwd)
dirname $(canonicalname "$1")
}
pkg_config_dependencies(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment