[augeas-devel] augeas: master - * src/augeas.c: report transforms under /augeas/load
David Lutterkort
lutter at fedoraproject.org
Fri Mar 20 00:04:17 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=d8b074ee739ec6b001e4122f5ab8a06c668d553a
Commit: d8b074ee739ec6b001e4122f5ab8a06c668d553a
Parent: d26170841cc7f5c894c401b2b2e99c2c44e09310
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Tue Mar 17 20:11:53 2009 -0700
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Mar 19 10:41:40 2009 -0700
* src/augeas.c: report transforms under /augeas/load
---
src/augeas.c | 92 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 71 insertions(+), 21 deletions(-)
diff --git a/src/augeas.c b/src/augeas.c
index 1dc836a..482d13e 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -94,6 +94,27 @@ static struct pathx *parse_user_pathx(const struct augeas *aug,
return NULL;
}
+static struct tree *tree_find(struct tree *origin, const char *path) {
+ struct pathx *px = NULL;
+ struct tree *result = NULL;
+
+ if (pathx_parse(origin, path, &px) != 0)
+ return NULL;
+
+ pathx_find_one(px, &result);
+ free_pathx(px);
+
+ return result;
+}
+
+static struct tree *tree_child(struct tree *tree, const char *label) {
+ list_for_each(child, tree->children) {
+ if (streqv(label, child->label))
+ return child;
+ }
+ return NULL;
+}
+
static const char *init_root(const char *root0) {
char *root;
@@ -114,6 +135,55 @@ static const char *init_root(const char *root0) {
return root;
}
+static struct tree *tree_append(struct tree *parent,
+ char *label, char *value) {
+ struct tree *result = make_tree(label, value, parent, NULL);
+ if (result != NULL)
+ list_append(parent->children, result);
+ return result;
+}
+
+static int tree_from_transform(struct augeas *aug,
+ const char *modname,
+ struct transform *xfm) {
+ struct tree *meta = tree_child(aug->origin, "augeas");
+ struct tree *load = NULL, *txfm = NULL;
+ char *m = NULL, *q = NULL;
+
+ if (meta == NULL)
+ return -1;
+
+ load = tree_child(meta, "load");
+ if (load == NULL) {
+ char *l = strdup("load");
+ load = tree_append(meta, l, NULL);
+ if (load == NULL)
+ return -1;
+ }
+ if (modname != NULL) {
+ m = strdup(modname);
+ if (m == NULL)
+ return -1;
+ } else {
+ m = strdup("_");
+ }
+ txfm = tree_append(load, m, NULL);
+ if (txfm == NULL)
+ return -1;
+
+ if (asprintf(&q, "@%s", modname) < 0)
+ return -1;
+
+ m = strdup("lens");
+ tree_append(txfm, m, q);
+ list_for_each(f, xfm->filter) {
+ char *glob = strdup(f->glob->str);
+ char *l = f->include ? strdup("incl") : strdup("excl");
+ tree_append(txfm, l, glob);
+ }
+ return 0;
+}
+
struct augeas *aug_init(const char *root, const char *loadpath,
unsigned int flags) {
struct augeas *result;
@@ -200,6 +270,7 @@ struct augeas *aug_init(const char *root, const char *loadpath,
struct transform *xform = modl->autoload;
if (xform == NULL)
continue;
+ tree_from_transform(result, modl->name, xform);
transform_load(result, xform);
}
tree_clean(result->origin);
@@ -614,27 +685,6 @@ static int update_save_flags(struct augeas *aug) {
return 0;
}
-static struct tree *tree_find(struct tree *origin, const char *path) {
- struct pathx *px = NULL;
- struct tree *result = NULL;
-
- if (pathx_parse(origin, path, &px) != 0)
- return NULL;
-
- pathx_find_one(px, &result);
- free_pathx(px);
-
- return result;
-}
-
-static struct tree *tree_child(struct tree *tree, const char *label) {
- list_for_each(child, tree->children) {
- if (streqv(label, child->label))
- return child;
- }
- return NULL;
-}
-
static int unlink_removed_files(struct augeas *aug,
struct tree *files, struct tree *meta) {
/* Find all nodes that correspond to a file and might have to be
More information about the augeas-devel
mailing list