@@ -6,8 +6,6 @@ bash_object.traverse-set() {
6
6
stdtrace.log 0 " CALL: bash_object.traverse-set: $* "
7
7
fi
8
8
9
- # TODO: errors if vmd_dtype, final_value_type is not one of the known ones
10
-
11
9
local final_value_type=" $1 "
12
10
local root_object_name=" $2 "
13
11
local filter=" $3 "
@@ -41,7 +39,6 @@ bash_object.traverse-set() {
41
39
# # be the name of a new _array_
42
40
# local new_current_object_name="__bash_object_${root_object_name}_tree_${key}_${RANDOM}_${RANDOM}_${RANDOM}_${RANDOM}_${RANDOM}"
43
41
44
- # # TODO: double-check if new_current_object_name only has underscores, dots, etc. (printf %q?)
45
42
# if ! eval "declare -gA $new_current_object_name=()"; then
46
43
# printf '%s\n' 'Error: bash-object: eval declare failed'
47
44
# return 1
@@ -55,34 +52,43 @@ bash_object.traverse-set() {
55
52
# If we are at the last element in the query
56
53
elif (( i+ 1 == ${# REPLIES[@]} )) ; then
57
54
if [ " $final_value_type " = object ]; then
58
- # TODO: late bash srandom
59
- local new_current_object_name=" __bash_object_${root_object_name} _tree_${key} _${RANDOM} _${RANDOM} _${RANDOM} _${RANDOM} _${RANDOM} "
60
-
61
- # TODO: test if name is already used
55
+ bash_object.util.generate_vobject_name
56
+ local new_current_object_name=" $REPLY "
62
57
63
58
# TODO: double-check if new_current_object_name only has underscores, dots, etc. (printf %q?)
64
59
65
- # 1. Create object
60
+ if (( BASH_VERSINFO[0 ] >= 5 )) || (( BASH_VERSINFO[0 ] == 4 && BASH_VERSINFO[1 ] >= 2 )) ; then
61
+ if [[ -v " $new_current_object_name " ]]; then
62
+ bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' " Autogenerated variable '$new_current_object_name ' already exists. Did RANDOM or SRANDOM get unset?"
63
+ return
64
+ fi
65
+ else
66
+ if ! eval "
67
+ if ! [ -z \$ {$new_current_object_name +x} ]; then
68
+ bash_object.util.die 'ERROR_INTERNAL_MISCELLANEOUS' \" Autogenerated variable '$new_current_object_name ' already exists. Did RANDOM or SRANDOM get unset?\"
69
+ return
70
+ fi
71
+ " ; then
72
+ bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' ' Eval unset test'
73
+ return
74
+ fi
75
+ fi
76
+
66
77
if ! eval " declare -gA $new_current_object_name =()" ; then
67
- # TODO: error
68
- printf ' %s\n' ' Error: bash-object: eval declare failed'
69
- return 1
78
+ bash_object.util.die ' ERROR_INTERNAL_MISCELLANEOUS' ' Eval declare failed'
79
+ return
70
80
fi
71
81
72
- # 2. Create virtual object
82
+ local -n new_current_object=" $new_current_object_name "
83
+
73
84
current_object[" $key " ]=$' \x1C\x1D ' " type=object;&$new_current_object_name "
74
85
75
- local -n new_current_object=" $new_current_object_name "
76
86
local -n object_to_copy=" $final_value "
77
87
# test if the object_to_copy is of the right type
78
88
for key in " ${! object_to_copy[@]} " ; do
79
89
new_current_object[" $key " ]=" ${object_to_copy["$key"]} "
80
90
done
81
91
elif [ " $final_value_type " = array ]; then
82
- # local new_current_object_name="__bash_object_${root_object_name}_tree_${key}_${RANDOM}_${RANDOM}_${RANDOM}_${RANDOM}_${RANDOM}"
83
- # current_object["$key"]=$'\x1C\x1D'"type=array;&$new_current_object_name"
84
-
85
- # local -n new_array = "$final_value"
86
92
:
87
93
# current_object["$key"]=("${new_array[@]}")
88
94
elif [ " $final_value_type " = string ]; then
0 commit comments