Hello Augeas experts,

I'm looking for a way to select a node in an Augeas tree in a distinct 
position, which isn't difficult, but I also want to create that node in case it 
doesn't exist yet, which seems impossible to me as of now. An example probably 
illustrates better what I mean...

augtool> touch /t/#comment
augtool> ins "" after /t/*[last()]
augtool> touch /t/B
augtool> touch /t/C
augtool> print /t
/t
/t/#comment
/t/
/t/B
/t/C


What can I do now to make a node "A" appear right in front of "B"? The straight 
forward answer is, like this:

insert "A" before "B"

That works fine as long as there is no "A" node already, which I can't know 
beforehand. I could guarantee that there is no such node, by deleting it first 
(this very trick was taken from the Augeas wiki: 
https://github.com/hercules-team/augeas/wiki/Path-expressions#Tips_amp_Tricks).

augtool> rm /t/A[following-sibling::*[1][self::B]]
rm : /t/A[following-sibling::*[1][self::B]] 0


However, this way I might destroy any children of "A", which henceforth are 
lost. In other words, I'd replace "A" instead of updating it.


Normally one selects specific nodes with 'defnode', which will create new nodes 
if no match was found.

augtool> defnode newNode /t/A[following-sibling::*[1][self::B]]
augtool> print /t
/t
/t/#comment
/t/
/t/B
/t/C
/t/A

The problem this time is, that the new node will be appended to tree in last 
position, so it needs to be moved to the correct position manually. And 'mv' in 
turn has the inherent drawback, that it cannot target relative positions, only 
specific destinations. Which means, replacing existing nodes, which I don't 
want.

Does someone maybe have a solution to this? Or is this another situation that 
needs to be dealt with by applications utilizting Augeas, since Augeas doesn't 
interpret the format of the files it edits?

Thank you for your time,
Xavier.

PS: I'll be on holidays next week, so I won't be able to answer any replies 
until I've returned.


****
Karlsruher Institute of Technology (KIT)
Steinbuch Centre for Computing (SCC)

B. Sc. Xavier Mol
GridKa Storage Administrator and Support Manager

Hermann-von-Helmholtz-Platz 1
Geb. 449
76344 Eggenstein-Leopoldshafen
Phone: +49 721 608 23041
Email: [email protected]
www.kit.edu
KIT - University of the State of Baden-Württemberg and National Large-scale 
Research Center of the Helmholtz Association
"Since 2010, the KIT has been certified as a family-friendly university."
****


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to