[augeas-devel] question about inserting entry to end, specifically with fstab lens

David Lutterkort lutter at redhat.com
Mon Feb 21 21:29:21 UTC 2011


On Thu, 2011-02-17 at 14:52 -0600, Greg_Swift at aotx.uscourts.gov wrote:
> The other suggests a hack of using a zero-padded number to append entries
> to the list,

This is not a hack - that is the recommended way to generate a label
that is guaranteed to be different from all the others in a numbered
sequence (even though I said number there, Augeas only knows strings)

>  I don't see how the ins method would work unless you know the number of
> the last entry.

Path expressions to the rescue:

        ins 01 after /files/etc/fstab/*[last()]
        
meaning 'insert the node 01 as the last child of /files/etc/fstab'

>   And to be quite honest, I can't figure out how to use
> insert to add a sequential entry anyway.  When I tried 'ins 7
> after /files/etc/fstab/6' I just got a 7 that was an entry not a node.
> Using 'set /files/etc/fstab/7/file /path' I get what I'm expecting.

You actually don't even need to bother with 'ins'. When you set the
value of a node that does not exist yet, it is automatically created.
The new node is always the last of its siblings, so that the following
will append the node '01' to the existing ones under /files/etc/fstab:

        defvar fstab /files/etc/fstab
        set $fstab/01/spec /dev/voo/doo
        set $fstab/01/file /voo/doo
        set $fstab/01/vfstype voodoo
        set $fstab/01/opt defaults
        set $fstab/01/dump 0
        set $fstab/01/passno 0
        save

Of course, when Augeas reads this back in, the '01' will be changed to
something else, maybe '8' - to make the above idempotent you have to
check, for example, if a node matching this path expression exists:

        /files/etc/fstab/*[spec = '/dev/voo/doo']

> The blog commenter's change from seq to label seems to work, and seems to
> be the more intuitive and effective method, but it requires a change to the
> lens and API  for that file that would likely cause regression issues.

Read Francis' high praise of seq from the other day ;) I don't think
changing the fstab lens is really desirable.

David





More information about the augeas-devel mailing list