Closed flo91 closed 1 year ago
Thanks for reporting the issue and providing just a detailed description.
Seems like elektraSetRawString
is simply broken.
This just calls elektraSaveKey
with a cascading key. So AFAICT this just adds a cascading key to the keyset within the Elektra
handle and then calls kdbSet
. Interesting that this went unnoticed for so long. It simply cannot work like this. We need a ksLookup
(or elektraFindKey
) somewhere.
However, as you saw with kdb set
. This still won't be enough, when there is only a default value. We'd need to choose a namespace. How this would best be achieved, I don't know.
Thank you for the quick response and the good explanation!
Hm, that seems like a serious issue.
I guess for the CM-homework it's best to explicitely give the user-namespace in the parameter of elektraOpen(...)
and provide a script that prepares the KDB
so that the application can work with it.
About choosing a namespace for new keys, I think the most natural behaviour would be
to use the user
-namespace for processes started by a user and the system
-namespace if the process was started by root.
If the key was already defined in the dir
-namespace, it should be written there.
On the other hand, if a process was started by a user and a value is saved, but a key only exists in the system
-namespace, I would create a new key in the user
-namespace.
But that's just a short first impression, there are for sure some problems and special cases that we have to consider.
Also a big thanks from me! Afaik the HL API was only used for getting values up-to-now. For the deadline today, we will simply ignore the setting keys in your submission (as StarHotel does not include setting keys at all, it would have been a bonus task anyway).
Parts of the report (about cascading kdb set
) are already covered in #4028.
The correct namespace to use for writing is application dependent. E.g. in KDE new config values are written to user:
, which is probably a sane default for the HL API. But as it is not the right choice for every application, we probably should provide a elektraSetCascadingWriteNamespace
to modify the namespace. (Adding a parameter to every elektraSet
call is maybe not so ideal, as it already has 4 parameters).
@kodebach do you think you can fix this in a reasonable timeframe so that @flo91 can use use it for the correction deadline?
we probably should provide a elektraSetCascadingWriteNamespace to modify the namespace.
I also thought about something like that. However, I'd simply call it elektraDefaultNamespace
:
// only ELEKTRA_NS_USER, ELEKTRA_NS_DIR and ELEKTRA_NS_SYSTEM are accepted
void elektraDefaultNamespace (Elektra * elektra, ElektraNamespace defaultNamespace)
As the name suggests, the namespace is used as a default, if a) currently no key exists at all or b) only a default:/
or proc:/
key exists. If a dir:/
, user:/
or system:/
key exists, we use that one (in this order, like always).
This should cover the common use case. If the need arises, we could also add:
// only ELEKTRA_NS_USER, ELEKTRA_NS_DIR and ELEKTRA_NS_SYSTEM are accepted
void elektraWriteNamespace (Elektra * elektra, ElektraNamespace writeNamespace)
This namespace would be used for all write operations no matter what keys do or don't exist already.
Note: There is no "set" in the function names, since elektraFatalErrorHandler
also doesn't have a "set" in the name
kodebach do you think you can fix this in a reasonable timeframe so that flo91 can use use it for the correction deadline?
If it is indeed as simple as I currently believe than yes, that should be possible.
Even if it is not urgent right now, we should not forget to fix this.
@markus2330 Probably a good FLOSS issue. The solution is basically described above, but there are still some details to work out for the implementor.
@markus2330 As @kodebach already mentioned, this issue seems good for the FLOSS course.
I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
Steps to Reproduce the Problem
While working on CM-H2, I noticed that the values are correctly read from the
KDB
, but setting of values fails silently, so everything seems to run smoothly and noElektraError
is set, but the changes are not written to theKDB
. I used the highlevel-API with code generation for the homework.To further investigate the issue, I tried a simplified version of the example which is available at https://github.com/ElektraInitiative/libelektra/tree/master/examples/highlevel. I used the cmake variant.
The exact code of my sample application is:
I used the specification from the example: https://github.com/ElektraInitiative/libelektra/blob/master/examples/highlevel/spec.ini
In the folder
/home/flo/tu/cm/elektra-0.9.9/examples/highlevel
I executed the following commands:Then I tried to query some values and got the default values as defined by the specification:
Following keys were available at that time: (standard system keys omitted)
Now I ran the application two times. The expected behaviour would be that the output of the second run should reflect the changes made by calling
elektraSetString
andelektraSetLong
. As you can see, no changes were written to theKDB
.Now I tried to manually set a new value for
mystring
using a cascading name:As you can see, the changed value was not returned by the
kdb get
with the same cascading name ordefault
-namespace.In the next step, I executed the
set
-command explicitly for theuser
-namespace. Now the value was saved and returned bykdb get
.But when running the application, the value was still not changed:
A
kdb set
with a cascading name was now working, because theuser
-namespace was used instead of thedefault
-namespace:But the application was still not working:
The "solution" I found was to add the
user
-namespace in theelektraOpen()
-call:I finally added the missing keys to the
user
-namespace, so that the applications runs successfully.But as you can see, now only the values that are explicitly available for the specified namespace are considered, so no cascading lookup was used any more which can lead to various problems... (e.g. no default values used)
Expected Result
The calls to
elektraSetString(...)
andelektraSetLong(...)
should change values in theKDB
.Actual Result
The values were not changed, unless giving a namespace in the call
elektraOpen(...)
System Information