Fix: libcrmcommon: correctly apply XML diffs with multiple move/create changes
Given a resource group:
<group id="dummies"> <primitive id="dummy0"/> <primitive id="dummy1"/> <primitive id="dummy2"/> <primitive id="dummy3"/> <primitive id="dummy4"/> </group>
, if we'd like to change it to:
<group id="dummies"> <primitive id="dummy3"/> <primitive id="dummy4"/> <primitive id="dummy2"/> <primitive id="dummy0"/> <primitive id="dummy1"/> </group>
, the generated XML diff would be like:
<diff format="2"> <change operation="move" path="//primitive[@id=dummy3]" position="0"/> <change operation="move" path="//primitive[@id=dummy4]" position="1"/> <change operation="move" path="//primitive[@id=dummy0]" position="3"/> <change operation="move" path="//primitive[@id=dummy1]" position="4"/> </diff>
Previously after applying the XML diff, the resulting XML would be a mess:
<group id="dummies"> <primitive id="dummy3"/> <primitive id="dummy4"/> <primitive id="dummy0"/> <primitive id="dummy2"/> <primitive id="dummy1"/> </group>
It's because the positions of the already moved XML objects could be
affected by the later moved objects.
This commit fixes it by temporarily putting "move" objects after the
last sibling and also delaying the adding of any "create" objects, then
placing them to the target positions in the right order.