[augeas-devel] augeas: master - * src/transform.c (add_file_info): manipulate tree directly

David Lutterkort lutter at fedoraproject.org
Thu Jan 7 20:40:33 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=bce5a8bfcd7e857c93b8b43e7ba4d057999396ca
Commit:        bce5a8bfcd7e857c93b8b43e7ba4d057999396ca
Parent:        1b55dd97290099cd15a412d3b382c25e27ff4275
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Jan 6 15:27:55 2010 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Jan 7 11:45:04 2010 -0800

* src/transform.c (add_file_info): manipulate tree directly

Going through public functions like aug_set is silly, and causes all kinds
of string munging.
---
 src/transform.c |   44 ++++++++++++++++++++------------------------
 1 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/src/transform.c b/src/transform.c
index 4f48826..9fe7712 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -326,44 +326,40 @@ static int store_error(struct augeas *aug,
  */
 static int add_file_info(struct augeas *aug,
                          const char *node, struct lens *lens) {
+    struct tree *file, *tree;
     char *tmp = NULL;
     int r;
-    char *p = NULL;
-    int end = 0;
+    char *path = NULL;
     int result = -1;
 
     if (lens == NULL)
         return -1;
 
-    r = pathjoin(&p, 2, AUGEAS_META_TREE, node);
-    if (r < 0)
-        goto done;
-    end = strlen(p);
-
-    r = pathjoin(&p, 1, s_path);
-    if (r < 0)
-        goto done;
+    r = pathjoin(&path, 2, AUGEAS_META_TREE, node);
+    ERR_NOMEM(r < 0, aug);
 
-    r = aug_set(aug, p, node);
-    if (r < 0)
-        goto done;
-    p[end] = '\0';
+    file = tree_find_cr(aug, path);
+    ERR_BAIL(aug);
 
-    r = pathjoin(&p, 1, s_lens);
-    if (r < 0)
-        goto done;
+    /* Set 'path' */
+    tree = tree_child_cr(file, s_path);
+    ERR_NOMEM(tree == NULL, aug);
+    r = tree_set_value(tree, node);
+    ERR_NOMEM(r < 0, aug);
 
+    /* Set 'lens' */
     tmp = format_info(lens->info);
-    if (tmp == NULL)
-        goto done;
-    r = aug_set(aug, p, tmp);
+    ERR_NOMEM(tmp == NULL, aug);
+    tree = tree_child_cr(file, s_lens);
+    ERR_NOMEM(tree == NULL, aug);
+    r = tree_set_value(tree, tmp);
+    ERR_NOMEM(r < 0, aug);
     FREE(tmp);
-    if (r < 0)
-        goto done;
 
     result = 0;
- done:
-    free(p);
+ error:
+    free(path);
+    free(tmp);
     return result;
 }
 




More information about the augeas-devel mailing list