[augeas-devel] augeas: master - aug_load: cleanup variables when deleting /files

David Lutterkort lutter at fedoraproject.org
Tue Aug 11 01:45:40 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=7630b4db3962d1f16b60d692e975b66855aeb3f3
Commit:        7630b4db3962d1f16b60d692e975b66855aeb3f3
Parent:        93aa81f70bcc2235ed8a5dc32a5d79baa1b4c4fd
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Mon Aug 10 18:40:44 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Aug 10 18:40:44 2009 -0700

aug_load: cleanup variables when deleting /files

The first thing aug_load does is delete /augeas/files and /files. We need
to make sure that any variables that contain references to nodes in those
subtrees are cleaned up properly, i.e. that we remove such nodes from
nodesets in the variables.

  * src/augeas.c (tree_unlink_children): remove descendants of the tree we
    are deleting from variables.
  * tests/test-load.c (testLoadDefined): verify fix

Fixes bug #79
---
 src/augeas.c      |    8 +++++---
 tests/test-load.c |   21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index b38dbf7..5e3c5ec 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -320,10 +320,12 @@ struct augeas *aug_init(const char *root, const char *loadpath,
     return NULL;
 }
 
-static void tree_unlink_children(struct tree *tree) {
+static void tree_unlink_children(struct augeas *aug, struct tree *tree) {
     if (tree == NULL)
         return;
 
+    pathx_symtab_remove_descendants(aug->symtab, tree);
+
     while (tree->children != NULL)
         tree_unlink(tree->children);
 }
@@ -337,8 +339,8 @@ int aug_load(struct augeas *aug) {
     if (load == NULL)
         return -1;
 
-    tree_unlink_children(meta_files);
-    tree_unlink_children(files);
+    tree_unlink_children(aug, meta_files);
+    tree_unlink_children(aug, files);
 
     list_for_each(xfm, load->children) {
         if (transform_validate(aug, xfm) == 0)
diff --git a/tests/test-load.c b/tests/test-load.c
index a181696..0310781 100644
--- a/tests/test-load.c
+++ b/tests/test-load.c
@@ -190,6 +190,26 @@ static void testLoadSave(CuTest *tc) {
     aug_close(aug);
 }
 
+/* Tests bug #79 */
+static void testLoadDefined(CuTest *tc) {
+    augeas *aug = NULL;
+    int r;
+
+    aug = aug_init(root, loadpath, AUG_NO_STDINC);
+    CuAssertPtrNotNull(tc, aug);
+
+    r = aug_defvar(aug, "v", "/files/etc/hosts/*/ipaddr");
+    CuAssertIntEquals(tc, 2, r);
+
+    r = aug_load(aug);
+    CuAssertRetSuccess(tc, r);
+
+    r = aug_match(aug, "$v", NULL);
+    CuAssertIntEquals(tc, 0, r);
+
+    aug_close(aug);
+}
+
 int main(void) {
     char *output = NULL;
     CuSuite* suite = CuSuiteNew();
@@ -200,6 +220,7 @@ int main(void) {
     SUITE_ADD_TEST(suite, testNoAutoload);
     SUITE_ADD_TEST(suite, testInvalidLens);
     SUITE_ADD_TEST(suite, testLoadSave);
+    SUITE_ADD_TEST(suite, testLoadDefined);
 
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (abs_top_srcdir == NULL)




More information about the augeas-devel mailing list