[augeas-devel] saving edited files in another directory

David Lutterkort lutter at redhat.com
Wed May 12 20:06:15 UTC 2010


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.

David

[1] https://www.redhat.com/archives/augeas-devel/2009-March/msg00195.html





More information about the augeas-devel mailing list