[augeas-devel] [PATCH] * src/augeas.h (aug_load): new public function

David Lutterkort lutter at redhat.com
Wed Mar 18 23:04:55 UTC 2009


---
 src/augeas.c           |   34 ++++++++++++++++++++++++++++++----
 src/augeas.h           |   31 +++++++++++++++++++++++++++++++
 src/augeas_sym.version |    1 +
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index 1f7073f..c3fc27a 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -274,13 +274,12 @@ struct augeas *aug_init(const char *root, const char *loadpath,
 
     list_for_each(modl, result->modules) {
         struct transform *xform = modl->autoload;
-        struct tree *txfm = NULL;
         if (xform == NULL)
             continue;
-        txfm = tree_from_transform(result, modl->name, xform);
-        transform_load(result, txfm);
+        tree_from_transform(result, modl->name, xform);
     }
-    tree_clean(result->origin);
+    if (aug_load(result) < 0)
+        goto error;
 
     return result;
 
@@ -289,6 +288,33 @@ struct augeas *aug_init(const char *root, const char *loadpath,
     return NULL;
 }
 
+static void tree_unlink_children(struct tree *tree) {
+    if (tree == NULL)
+        return;
+
+    while (tree->children != NULL)
+        tree_unlink(tree->children);
+}
+
+int aug_load(struct augeas *aug) {
+    struct tree *meta = tree_child(aug->origin, "augeas");
+    struct tree *meta_files = tree_child(meta, "files");
+    struct tree *files = tree_child(aug->origin, "files");
+    struct tree *load = tree_child(meta, "load");
+
+    if (load == NULL)
+        return 0;
+
+    tree_unlink_children(meta_files);
+    tree_unlink_children(files);
+
+    list_for_each(xfm, load->children) {
+        transform_load(aug, xfm);
+    }
+    tree_clean(aug->origin);
+    return 0;
+}
+
 int aug_get(const struct augeas *aug, const char *path, const char **value) {
     struct pathx *p;
     struct tree *match;
diff --git a/src/augeas.h b/src/augeas.h
index 03ed324..b2f32f8 100644
--- a/src/augeas.h
+++ b/src/augeas.h
@@ -180,6 +180,37 @@ int aug_match(const augeas *aug, const char *path, char ***matches);
  */
 int aug_save(augeas *aug);
 
+/* Function: aug_load
+ *
+ * Load files into the tree. Which files to load and what lenses to use on
+ * them is specified under /augeas/load in the tree; each entry
+ * /augeas/load/NAME specifies a 'transform', by having itself exactly one
+ * child 'lens' and any number of children labelled 'incl' and 'excl'. The
+ * value of NAME has no meaning.
+ *
+ * The 'lens' grandchild of /augeas/load specifies which lens to use, and
+ * can either be the fully qualified name of a lens 'Module.lens' or
+ * '@Module'. The latter form means that the lens from the transform marked
+ * for autoloading in MODULE should be used.
+ *
+ * The 'incl' and 'excl' grandchildren of /augeas/load indicate which files
+ * to transform. Their value are used as glob patterns. Any file that
+ * matches at least one 'incl' pattern and no 'excl' pattern is
+ * transformed. The order of 'incl' and 'excl' entries is irrelevant.
+ *
+ * When AUG_INIT is first called, it populates /augeas/load with the
+ * transforms marked for autoloading in all the modules it finds.
+ *
+ * Before loading any files, AUG_LOAD will remove everything underneath
+ * /augeas/files and /files, regardless of whether any entries have been
+ * modified or not.
+ *
+ * Returns -1 on error, 0 on success. Note that success includes the case
+ * where some files could not be loaded. Details of such files can be found
+ * as '/augeas//error'.
+ */
+int aug_load(augeas *aug);
+
 /* Function: aug_print
  *
  * Print each node matching PATH and its descendants to OUT.
diff --git a/src/augeas_sym.version b/src/augeas_sym.version
index 26c858c..e479d13 100644
--- a/src/augeas_sym.version
+++ b/src/augeas_sym.version
@@ -9,6 +9,7 @@
       aug_mv;
       aug_match;
       aug_save;
+      aug_load;
       aug_print;
       # Symbols with __ are private
       __aug_load_module_file;
-- 
1.6.0.6




More information about the augeas-devel mailing list