Browse Source

functions: introduced pseudo_realpath() sanitizing paths

user/chris/test/patchcksum
Alejandro Mery 13 years ago
parent
commit
4a1ac2ba2c
1 changed files with 35 additions and 0 deletions
  1. +35
    -0
      lib/functions.in

+ 35
- 0
lib/functions.in

@ -107,6 +107,41 @@ bz2filename() {
fi
}
# pseudo_realpath <path>
# returns a clean absolute path without caring about symlinks or actual existance
#
pseudo_realpath() {
local origpath="$1"
local newpath= x=
local path="$(echo "$1" | sed -e "s,^\([^/]\),$PWD/\1," )"
while [ -n "$path" ]; do
x="${path%%/*}"
if [ "$x" = "$path" ]; then
path=
else
path="${path#*/}"
fi
case "$x" in
""|.)
;; # skip
..)
if [ -n "$newpath" ]; then
newpath="${newpath%/*}"
else
echo "$origpath: invalid" >&2
return
fi
;;
*)
newpath="$newpath/$x"
esac
done
echo "$newpath"
}
# Hook variables
#
unset hook_functions hook_fcounter

Loading…
Cancel
Save