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