libelektra
libelektra copied to clipboard
elektraMerge fails if the root is top of a namespace
Steps to Reproduce the Problem
KeySet* ksBase = ksNew (0, KS_END);
KeySet* ksOurs = ksNew(0, KS_END);
KeySet* ksTheirs = ksNew (0, KS_END);
Key* baseRoot = keyNew ("system:/", KEY_END);
Key* oursRoot = keyNew ("system:/", KEY_END);
Key* theirsRoot = keyNew ("system:/", KEY_END);
Key* root = keyNew ("system:/", KEY_END);
ksAppendKey (ksBase, keyNew ("system:/test/k1", "k1", KEY_END));
ksAppendKey (ksOurs, keyNew ("system:/test/k1", "k1", KEY_END));
ksAppendKey (ksOurs, keyNew ("system:/test/k2", "k2", KEY_END));
ksAppendKey (ksTheirs, keyNew ("system:/test/k1", "k1", KEY_END));
ksAppendKey (ksTheirs, keyNew ("system:/test/k3", "k3", KEY_END));
Key* information = keyNew ("system:/", KEY_END);
KeySet* result = elektraMerge (ksOurs, oursRoot, ksTheirs, theirsRoot, ksBase, baseRoot, root, 1, information);
Expected Result
result contains the keys system:/test/k1, system:/test/k2 and system:/test/k3.
Actual Result
result is NULL
Why?
Internally, the algorithm will try to rename the keys in the keyset by removing the root name from the key name.
For example, system:/test/k1 will be renamed to test/k1. However, this is not a valid key name as it does not start with a slash. This makes the rename operation fail.
Seems like the merge algorithm doesn't correctly handle the fact, that root names end with a slash. Not sure how exactly the renaming is done, but it seems a good candidate for this function
https://github.com/ElektraInitiative/libelektra/blob/7f3f343cabcec561c87de8b41fbeae552699d697/src/libs/elektra/keyset.c#L1097
(I think it's currently only declared in kdbprivate.h)
It uses keySetName.
https://github.com/ElektraInitiative/libelektra/blob/7f3f343cabcec561c87de8b41fbeae552699d697/src/libs/merge/kdbmerge.c#L313
There is also this function
https://github.com/ElektraInitiative/libelektra/blob/7f3f343cabcec561c87de8b41fbeae552699d697/src/libs/elektra/keyname.c#L679
which may be a better fit.
In any case, I think the keySetName with the custom strremove should be replaced. AFAICT it doesn't handle escape sequences like \/ at all and may cause more problems than just this issue.
@markus2330 This looks also like an issue suited 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: