sane-sandboxed: be a little more careful with out vars
This commit is contained in:
parent
e6b13adb61
commit
6c65e4b313
|
@ -185,18 +185,21 @@ splitHead() {
|
|||
# does not resolve symlinks, nor check for existence of any component of the path.
|
||||
normPath() {
|
||||
local npOut="$1"
|
||||
_npUnparsed="$2"
|
||||
local npUnparsed="$2"
|
||||
local npComps=()
|
||||
while [ -n "$_npUnparsed" ]; do
|
||||
splitHead _npThisComp _npUnparsed "$_npUnparsed"
|
||||
if [ "$_npThisComp" = "/.." ]; then
|
||||
npUnparsed="$_npUnparsed"
|
||||
local npThisComp="$_npThisComp"
|
||||
|
||||
if [ "$npThisComp" = "/.." ]; then
|
||||
# "go up" path component => delete the leaf dir (if any)
|
||||
if [ ${#npComps[@]} -ne 0 ]; then
|
||||
unset npComps[-1]
|
||||
fi
|
||||
elif [ "$_npThisComp" != "/." ] && [ "$_npThisComp" != "/" ] && [ "$_npThisComp" != "" ]; then
|
||||
elif [ "$npThisComp" != "/." ] && [ "$npThisComp" != "/" ] && [ "$npThisComp" != "" ]; then
|
||||
# normal, non-empty path component => append it
|
||||
npComps+=("$_npThisComp")
|
||||
npComps+=("$npThisComp")
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -308,13 +311,15 @@ derefOnce() {
|
|||
local target=
|
||||
|
||||
local walked=
|
||||
_unwalked="$source"
|
||||
while [ -n "$_unwalked" ]; do
|
||||
local unwalked="$source"
|
||||
while [ -n "$unwalked" ]; do
|
||||
splitHead _head _unwalked "$_unwalked"
|
||||
unwalked="$_unwalked"
|
||||
walked="$walked$_head"
|
||||
readlinkOnce linkTarget "$walked"
|
||||
if [ -n "$linkTarget" ]; then
|
||||
target="$linkTarget$_unwalked"
|
||||
|
||||
readlinkOnce _linkTarget "$walked"
|
||||
if [ -n "$_linkTarget" ]; then
|
||||
target="$_linkTarget$unwalked"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -413,24 +418,25 @@ tryPath() {
|
|||
tryArgAsPath() {
|
||||
local arg="$1"
|
||||
local how="$2"
|
||||
_path=
|
||||
path=
|
||||
if [ "${arg:0:1}" = "/" ]; then
|
||||
# absolute path
|
||||
_path="$_arg"
|
||||
path="$arg"
|
||||
elif [ "${arg:0:8}" = "file:///" ]; then
|
||||
# URI to an absolute path which is presumably on this vfs
|
||||
# commonly found when xdg-open/mimeo passes a path on to an application
|
||||
# if URIs to relative paths exist, this implementation doesn't support them
|
||||
urldecode _path "${arg:7}"
|
||||
elif [ "${_path:0:1}" = "-" ]; then
|
||||
path="$_path"
|
||||
elif [ "${path:0:1}" = "-" ]; then
|
||||
# 99% chance it's a CLI argument. if not, use `./-<...>`
|
||||
return
|
||||
else
|
||||
# assume relative path
|
||||
_path="$PWD/$_arg"
|
||||
_path="$PWD/$arg"
|
||||
fi
|
||||
|
||||
tryPath "$_path" "$how"
|
||||
tryPath "$path" "$how"
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user