[augeas-devel] saving edited files in another directory

Christopher Harvey chris at basementcode.com
Thu May 13 12:48:36 UTC 2010


On 05/12/10 16:06, David Lutterkort wrote:
> On Wed, 2010-05-12 at 13:36 -0400, Christopher Harvey wrote:
>> I want to write a patch that lets users get a diff between the original
>> and the modified without needing to be able to write to the directory
>> that contains the original. Is this an interesting feature? Could
>> somebody give me a general direction of how this should work internally
>> with Augeas?
> 
> Yes, that would indeed be very interesting. It's related to another
> feature I've been wanting to add to the API: transformation between a
> string (not a file) and a tree back and forth.
> 
> There was some discussion about that a while ago[1] - the basic idea is
> to provide two new API functions, aug_lens_get an aug_lens_put that let
> you take a string and transform it into a tree (the get call), or take
> part of the big tree and transform it back into a string. The signatures
> would be something like
> 
>   int aug_lens_get(struct augeas *, const char *lens,
>                    const char *path,
> 	           const char *text, size_t text_len);
> 
>   int aug_lens_put(struct augeas *, const char *lens,
>                    const char *path,
> 	           const char *text, size_t text_len,
>                    char **new_text, size_t new_text_len);
> 
> Here, LENS is the name of a lens, say "Hosts.lns", PATH is the path to
> the subtree of interest, say "/files/etc/hosts", TEXT is the original
> string, and NEW_TEXT a pointer to the newly allocated string resulting
> from transforming the tree at PATH back int a string.
> 
> There could of course also be a mix of the approaches; you seem to be
> mostly interested in letting Augeas load from file, but then transform
> the tree back into a string, not a file.
> 
> The guts of the file/tree transformation is in transform.c:
> transform_load reads a file and turns it into a tree, transform_save
> does the reverse. Doing the same thing with strings would be a lot
> simpler, since you don't need to worry about any file system-related
> errors.

I took a look at the relevant code in augeas. Looks like all writes take
place in put_lens. put_lens is divided over put_del, put_store,
put_concat, put_subtree, etc..
All of those functions output to a file pointer directly. As far as I
can tell the only way to implement aug_lens_put without major surgery to
create string based implementations of those functions would be to have
the state object tell the functions, "don't output to the file! output
to this new string pointer!".
Would that change be ok to add to augeas? Is there an easier way?

> 
> David
> 
> [1] https://www.redhat.com/archives/augeas-devel/2009-March/msg00195.html
> 
> 
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel


-- 
My GnuPGP key at:
www.basementcode.com/public_key.txt




More information about the augeas-devel mailing list