Elektra  0.9.3
Arrays

Currently it is inefficient to detect the length of an array and it is impossible to know if a key (without subkeys) should be an array or not.

Store length in metadata array of key, or keep metadata array empty if empty array. For example (ni syntax, sections used for metadata):

myarray/#0 = value0
myarray/#1 = value1
myarray/#2 = value2
myarray/#3 = value3
myarray/#4 = value4
myarray/#5 = value5
[myarray]
array = #5

It is not allowed to have anything else than #5 in the metadata array, e.g. even #4 would be a malformed array.

The metadata array preferable should be in spec (specified configuration). Then the spec plugin will add the array marker with the correct length. This needs to be happen early, so that plugins can rely on having correct arrays.

For example:

spec:/myarray # <- has array marker
user:/myarray # <- either has correct array marker or no array marker
user:/myarray/#0
user:/myarray/#1

Here, the spec plugin would add array=#1 to user:/myarray if it was not there before.

To lookup an array, first do ksLookupByName (ks, "/myarray", 0) on the parent. With the last index you get from its metadata array, iterate over the children. A cascading lookup on every individual child is also needed to make sure that overrides on individual elements are respected.

For example:

spec:/myarray # <- contains the specification for the array
spec:/myarray/# # <- contains the specification for the array elements
dir:/myarray/#0 # <- not an array, just an override for user:/myarray/#
user:/myarray # <- with metadata array=#0, this would be the array we get
user:/myarray/#0
system:/myarray # <- not found in cascading lookup, as user:/myarray exists

Guarantees we want from the spec plugin:

https://github.com/ElektraInitiative/libelektra/issues/182