Fix processingi of irregular pathes liks ///tmp//./b/.

This commit is contained in:
2022-03-21 14:56:44 +01:00
parent 3d9113377c
commit 621da5e4c8

View File

@@ -21,10 +21,11 @@ rl::rdlink() {
local work=
local resolved=0
info "pwd: $(pwd)"
info "Processing... $@"
info "rd::link Processing... $@"
info " pwd: $(pwd)"
subject="$(rl::cleanpath "${1:-}")" || true
subject="$(rl::normalize "${1:-}")" || true
# Follow multiple symlinks
while subject="$(rl::quicklink "${subject}")" ; do
# A link was resolved at least once
@@ -49,11 +50,11 @@ rl::rdlink() {
# Special: Links resolved to something like: /proc/2267178/fd/pipe:[22306727]
# are not existing files but `readlink -f` prints result anyway
# Printing result if a link was resolved at least once
if (( ! resolved )); then
#if (( ! resolved )); then
info "rl::rdlink exit - invalid path ${subject}"
printf "\n"
return 1
fi
#fi
else
subject="${work}"
fi
@@ -115,9 +116,11 @@ rl::canon() {
return 0
}
rl::normalize() {
rl::cleanpath() {
local work=
info "Normalizing... ${1:-}"
local rex_tmp=
info "rl::cleanpath...${1:-}"
work="${1:-}"
# Remove multiple /
@@ -125,6 +128,38 @@ rl::normalize() {
work="${work//'//'/'/'}"
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"
}