Retrieving last modified node path (Was: [augeas-devel] First tests with aug mv)

Raphaël Pinson raphink at gmail.com
Fri Aug 1 09:14:21 UTC 2008


On Wed, Jul 30, 2008 at 7:44 AM, Raphaël Pinson <raphink at gmail.com> wrote:

>
>
> On Wed, Jul 30, 2008 at 1:06 AM, David Lutterkort <dlutter at redhat.com>wrote:
>
>> On Wed, 2008-07-30 at 00:14 +0200, Raphaël Pinson wrote:
>> >
>> >
>> > On Tue, Jul 29, 2008 at 9:02 PM, David Lutterkort <dlutter at redhat.com>
>> > wrote:
>>
>> >         New nodes are always added at the end (the same is true for
>> >         'set')
>> >
>> > That's useful indeed. I think it would be even more useful if
>> > aug_insert returned the path of the newly inserted node. Let's say
>> > there's already a .field before the one I'm inserting. Then this would
>> > be useful:
>> >
>> > $to_move = "/files/commenttest/field[1]";
>> > $c_field = aug_ins(".field", "after", $to_move);
>> > => $c_field = "/files/commenttest/.field[2]"
>> > aug_mv($to_move, $c_field);
>>
>> Yes, that would indeed be useful; unfortunately, that's not supported by
>> the API right now, and would require adding a new call.
>>
>

After talking with David on IRC, I now understand that modifying tree_insert
to return the path to the created node would mean to modify the API, which
is not acceptable. David proposes another approach, which would be to store
the path to this new node in /augeas/last_created_node.

After thinking about this, I think a /augeas/last_modified_node would
actually be more useful, although the most obvious use of it would be for
insert.

With insert, this is an obvious need :
aug_ins("field", "after", path) does not give me any information on the node
that was created, so I have no clue on what path to pass to aug_set or
aug_rm if I want to set or remove this node.

On the other hand, 'aug_set("/files/etc/my/file/field[100]", "value")' or
'aug_set("/files/etc/my/file/field[last()]", "value")' do not give me any
information either on the exact path to the node I just modified, but
contrarily to aug_insert, I can still refer to this modified node as
"/files/etc/my/file/field[100]" or "/files/etc/my/file/field[last()]".

I think it could be interesting to have a /augeas/last_modified_node where
every function (whether insert, set, rm, mv, etc.) would write the name of
the last modified node, so that the user can retrieve it to reuse it:

So David's proposition:

[18:50] <lutter> aug.insert(".field", "/some/where/field", BEFORE)
[18:50] <lutter> path = aug.get("/augeas/last_created_node")
[18:50] <lutter> aug.set(path + "/foo", "value")


would become:

aug.insert(".field", "/some/where/field", BEFORE)
path = aug.get("/augeas/last_modified_node")
aug.set(path + "/foo", "value")

aut.set("/some/other/field[last()]", "value")
newpath = aug.get("/augeas/last_modified_node")
puts newpath+" was modified"



Raphael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080801/5c8a5d8c/attachment.htm>


More information about the augeas-devel mailing list