funcionts (CanonPath): use two-pass canonicalization
This removes the ambiguity with directories. Note that before this change, e.g. [ -L /etc/init.d ] and [ -L /etc/init.d/ ] would yield different result, which required ad hock -d test to keep things consistent. With first-pass "blind" (cleanup-only) canonicalization, ad hock test for directories is no longer required, and things are yet more consistent. The things are now consistent with documented behaviour -- "canonicalize each path component except for the last". This actually changed previous behaviour: was: /etc/init.d -> /etc/rc.d/init.d now: /etc/init.d -> /etc/init.d Generally, if we have some path for which we should yield a dependency, CanonPath is probably the best we can do before running e.g. contents_index search.
This commit is contained in:
parent
5b353de0eb
commit
78a8d8e533
@ -99,20 +99,27 @@ RunMethods()
|
||||
done
|
||||
}
|
||||
|
||||
# Canonicalize each path component with respect to symbolic links, except
|
||||
# for the last. E.g. /etc/init.d/functions -> /etc/rc.d/init.d/functions.
|
||||
CanonPath()
|
||||
{
|
||||
local f="$1" f2; shift
|
||||
if [ -d "$f" ]; then
|
||||
f2=$(readlink -vm -- "$f")
|
||||
elif [ -L "$f" ]; then
|
||||
local f0="${1:?}" f1 f2; shift
|
||||
[ -z "${f0##/*}" ] || f0=$PWD/$f0
|
||||
# First pass: "blind" cleanup-only canonicalization.
|
||||
f1=$(readlink -vm "/-$$-/$f0")
|
||||
f1=${f1##/-$$-}
|
||||
[ "$f0" = "$f1" ] || Verbose "CanonPath1: $f0 -> $f1"
|
||||
# Second pass: adjust parent directory.
|
||||
# Note that -L test was not reliable before the first pass.
|
||||
if [ -L "$f1" ]; then
|
||||
local d
|
||||
d=$(dirname -- "$f")
|
||||
d=$(dirname -- "$f1")
|
||||
d=$(readlink -vm -- "$d")
|
||||
f2="$d/${f##*/}"
|
||||
f2="${d%/}/${f1##*/}"
|
||||
else
|
||||
f2=$(readlink -vm -- "$f")
|
||||
f2=$(readlink -vm -- "$f1")
|
||||
fi
|
||||
[ "$f" = "$f2" ] || Verbose "CanonPath: $f -> $f2"
|
||||
[ "$f1" = "$f2" ] || Verbose "CanonPath2: $f1 -> $f2"
|
||||
echo "$f2"
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user