[augeas-devel] Create file from scratch

David Lutterkort lutter at redhat.com
Mon May 24 11:22:56 UTC 2010


On Sat, 2010-05-22 at 08:27 -0400, Francis Giraldeau wrote:
> Hi,
> 
> I tried to create a file from scratch. While it works while setting a
> value of a node, it seems that if the node doesn't have a value, we
> can't add it from an empty tree. 
> 
>   (* lens with key-value : set creates the node, everything ok *)
>   let y = [ key /[a-c]/ . store /[0-9]/]* 
>   test y put "" after set "/c" "3" = "c3"
> 
>   (* lens without value, can't create the key *)
>   let x = [ key /[a-c]/ ]*               
>   test x put "" after insa "a" "/" = ""
>   test x put "" after set "/a" "foo" = *
> 
> I think that rising an error on set when the actual node doesn't have a
> value is correct. But, insa should match the empty tree in some way,
> isnt't?

You've hit upon a corner case of path expressions: "/" is not a valid
path expression, and there's no way to modify the root node of the tree.
I am not sure why that doesn't lead to an error in the test, but it's
not directly the problem you're having.

The command 'insa "a" "/"' says 'insert node "a" after the root node' -
which is clearly not what you want. You want something like 'set
"/a" ???', though since set takes two strings (one for the path to the
node, and one for its value), and since the value can be any string,
there's no way to express 'set the value to NULL'

What you want is 'clear "/a"'. 'clear' behaves like 'set', except it
sets the value of the node to NULL.

David





More information about the augeas-devel mailing list