[augeas-devel] [PATCH] Write last created node in /augeas/tree/last_created for tree_create and tree_insert

Raphaël Pinson raphink at gmail.com
Fri Aug 8 20:57:30 UTC 2008


On Fri, Aug 8, 2008 at 10:12 PM, David Lutterkort <dlutter at redhat.com>wrote:

> On Fri, 2008-08-08 at 20:25 +0200, Raphaël Pinson wrote:
> > Hmmm now I realize why doing this in the tree_* functions could be
> > nasty, since /augeas/tree/last_created will be set when nodes
> > in /augeas are set...
> >
> > I dont' really know how to do it though... I see two options:
> > * Checking if the first segment of the path is /augeas and not
> > setting /augeas/tree/last_created in this case
> > * Modifying the internal API so the tree_create and tree_insert
> > functions can return the created path and the aug_* functions can
> > set /augeas/tree/last_created.
>
> Yes, I think that would be the cleanest solution: tree_insert should
> become
>
>        int tree_insert(struct tree **tree, const char *path, const char
> *label,
>                        int before, struct path **node)
>
> and the line 'free_path(p)' should become
>
>        if (node != NULL) {
>          *node = p;
>        } else {
>          free_path(p);
>        }
>
> and aug_insert would turn into
>
>        int aug_insert(struct augeas *aug, const char *path, const char
> *label,
>                       int before) {
>         struct path *node = NULL;
>         char *s = NULL;
>         int ret = -1, r;
>
>            r = tree_insert(&(aug->tree), path, label, before, &node);
>            if (r < 0)
>               goto done;
>
>            char *s = format_path(node);
>            if (s == NULL)
>               goto done;
>
>            if (tree_set(root, AUGEAS_META_LAST_CREATED, s) == NULL)
>               goto done;
>
>            ret = 0;
>          done:
>              FREE(s);
>              free_path(node);
>              return ret;
>        }
>
> (Isn't error checking fun ?)
>
>
Yes, that would work here. But how about the tree_create function?
tree_create is called from tree_set and aug_mv (and will be called from
aug_cp and it's done). Should each of aug_set, aug_mv and aug_cp deal with
the node and both tree_create and tree_set calls be changed?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080808/6fb7a062/attachment.htm>


More information about the augeas-devel mailing list