mirror of
https://github.com/ARM-software/devlib.git
synced 2025-03-03 16:57:51 +00:00
Target: fix read_tree_values for empty dir
grep was existing with 1 when passed an empty directory, resulting in TargetError being raised unless explicitly suppressed with check_exit_code=False. This case is now fixed to correctly return an empty dict without error. read_tree_values bash function has also been optimized to not unnecessarily run find in a subshell if the path passed to the function does not exist.
This commit is contained in:
parent
4d8da589f8
commit
d560aea660
@ -216,10 +216,13 @@ read_tree_values() {
|
|||||||
PATH=$1
|
PATH=$1
|
||||||
MAXDEPTH=$2
|
MAXDEPTH=$2
|
||||||
|
|
||||||
|
if [ ! -e $PATH ]; then
|
||||||
|
echo "ERROR: $PATH does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
PATHS=$($BUSYBOX find $PATH -follow -maxdepth $MAXDEPTH)
|
PATHS=$($BUSYBOX find $PATH -follow -maxdepth $MAXDEPTH)
|
||||||
if [ ${#PATHS[@]} -eq 0 ]; then
|
if [ ${#PATHS[@]} -gt 1 ]; then
|
||||||
echo "ERROR: '$1' does not exist"
|
|
||||||
else
|
|
||||||
$BUSYBOX grep -s '' $PATHS
|
$BUSYBOX grep -s '' $PATHS
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -620,6 +620,8 @@ class Target(object):
|
|||||||
check_exit_code=check_exit_code)
|
check_exit_code=check_exit_code)
|
||||||
result = {}
|
result = {}
|
||||||
for entry in output.strip().split('\n'):
|
for entry in output.strip().split('\n'):
|
||||||
|
if not entry.strip():
|
||||||
|
continue
|
||||||
path, value = entry.strip().split(':', 1)
|
path, value = entry.strip().split(':', 1)
|
||||||
result[path] = value
|
result[path] = value
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user