[augeas-devel] [PATCH] Write last created node in /augeas/tree/last_created for tree_create and tree_insert
David Lutterkort
dlutter at redhat.com
Fri Aug 8 20:12:25 UTC 2008
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 ?)
More information about the augeas-devel
mailing list