Fix processingi of irregular pathes liks ///tmp//./b/.
This commit is contained in:
49
rdlink.sh
49
rdlink.sh
@@ -21,10 +21,11 @@ rl::rdlink() {
|
|||||||
local work=
|
local work=
|
||||||
local resolved=0
|
local resolved=0
|
||||||
|
|
||||||
info "pwd: $(pwd)"
|
info "rd::link Processing... $@"
|
||||||
info "Processing... $@"
|
info " pwd: $(pwd)"
|
||||||
|
|
||||||
|
subject="$(rl::cleanpath "${1:-}")" || true
|
||||||
|
|
||||||
subject="$(rl::normalize "${1:-}")" || true
|
|
||||||
# Follow multiple symlinks
|
# Follow multiple symlinks
|
||||||
while subject="$(rl::quicklink "${subject}")" ; do
|
while subject="$(rl::quicklink "${subject}")" ; do
|
||||||
# A link was resolved at least once
|
# A link was resolved at least once
|
||||||
@@ -49,11 +50,11 @@ rl::rdlink() {
|
|||||||
# Special: Links resolved to something like: /proc/2267178/fd/pipe:[22306727]
|
# Special: Links resolved to something like: /proc/2267178/fd/pipe:[22306727]
|
||||||
# are not existing files but `readlink -f` prints result anyway
|
# are not existing files but `readlink -f` prints result anyway
|
||||||
# Printing result if a link was resolved at least once
|
# Printing result if a link was resolved at least once
|
||||||
if (( ! resolved )); then
|
#if (( ! resolved )); then
|
||||||
info "rl::rdlink exit - invalid path ${subject}"
|
info "rl::rdlink exit - invalid path ${subject}"
|
||||||
printf "\n"
|
printf "\n"
|
||||||
return 1
|
return 1
|
||||||
fi
|
#fi
|
||||||
else
|
else
|
||||||
subject="${work}"
|
subject="${work}"
|
||||||
fi
|
fi
|
||||||
@@ -115,16 +116,50 @@ rl::canon() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
rl::normalize() {
|
rl::cleanpath() {
|
||||||
local work=
|
local work=
|
||||||
info "Normalizing... ${1:-}"
|
local rex_tmp=
|
||||||
|
|
||||||
|
info "rl::cleanpath...${1:-}"
|
||||||
|
|
||||||
work="${1:-}"
|
work="${1:-}"
|
||||||
# Remove multiple /
|
# Remove multiple /
|
||||||
while [[ "${work:-}" = *"//"* ]]; do
|
while [[ "${work:-}" = *"//"* ]]; do
|
||||||
work="${work//'//'/'/'}"
|
work="${work//'//'/'/'}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
info "rl::cleanpath result: ${work}"
|
||||||
|
printf -- "${work}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
rl::normalize() {
|
||||||
|
local work=
|
||||||
|
|
||||||
|
info "rl::normalize...${1:-}"
|
||||||
|
|
||||||
|
work="${1:-}"
|
||||||
|
# Remove dir/.. sequences.
|
||||||
|
local rex_tmp='[^/][^/]*/\.\./*'
|
||||||
|
while [[ "${work}" =~ $rex_tmp ]] ; do
|
||||||
|
work="${work/"${BASH_REMATCH[0]}"/}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove /./ or /.$ sequences.
|
||||||
|
rex_tmp='/\.(/|$)'
|
||||||
|
while [[ "$work" =~ $rex_tmp ]]; do
|
||||||
|
work="${work/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]/$//}"}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove leading ./
|
||||||
|
work="${work#./*}"
|
||||||
|
|
||||||
|
# Remove trailing /
|
||||||
|
rex_tmp='(.*[^/])/$'
|
||||||
|
if [[ "${work}" =~ $rex_tmp ]] ; then
|
||||||
|
work="${BASH_REMATCH[1]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "rl::normalize result: ${work}"
|
||||||
printf -- "${work}\n"
|
printf -- "${work}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user