[augeas-devel] augeas: master - tree handling: propagate dirty flag into root
David Lutterkort
lutter at fedoraproject.org
Fri Jul 10 01:24:36 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=6c758c297ac8b1739c9ecd25ec3d13813904be3b
Commit: 6c758c297ac8b1739c9ecd25ec3d13813904be3b
Parent: ca6f8ad8da5ab1c659d986ffcaa56683a19419e6
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Thu Jul 9 17:31:01 2009 -0700
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Jul 9 18:08:33 2009 -0700
tree handling: propagate dirty flag into root
We had an off-by-one error in tree_mark_dirty that lead to the root of the
tree not being marked as dirty. As a consequence, performing a tree_clean
on such a tree would not mark the tree as clean; that caused an aug_load
directly followed by aug_save to write to disk, even though the tree was
unchanged.
* src/augeas.c (tree_mark_dirty): propagate dirty flag to the root
* tests/test-load.c (testLoadSave): test that simple load + save
does not touch the filesystem
This bug was introduced in commit 7278965b
---
src/augeas.c | 1 +
tests/test-load.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/src/augeas.c b/src/augeas.c
index 90b51f9..62339c5 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -56,6 +56,7 @@ static void tree_mark_dirty(struct tree *tree) {
tree->dirty = 1;
tree = tree->parent;
} while (tree != tree->parent && !tree->dirty);
+ tree->dirty = 1;
}
/* Clear the dirty flag in the whole TREE */
diff --git a/tests/test-load.c b/tests/test-load.c
index d3eb790..a181696 100644
--- a/tests/test-load.c
+++ b/tests/test-load.c
@@ -158,6 +158,38 @@ static void testInvalidLens(CuTest *tc) {
aug_close(aug);
}
+static void testLoadSave(CuTest *tc) {
+ augeas *aug = NULL;
+ int r;
+
+ /* FIXME: This test behaves properly during distcheck, since srcdir
+ * is writeprotected, making an incorrect attempt to write
+ * /etc/hosts.augnew fail; during normal 'make check' the test will
+ * succeed.
+ * To address this, we should copy the files fro, tests/root into
+ * another directory and 'chmod a-w /etc' in that root
+ */
+ aug = aug_init(root, loadpath, AUG_NO_MODL_AUTOLOAD|AUG_SAVE_NOOP);
+ CuAssertPtrNotNull(tc, aug);
+
+ r = aug_set(aug, "/augeas/load/Hosts/lens", "Hosts.lns");
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_set(aug, "/augeas/load/Hosts/incl", "/etc/hosts");
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_load(aug);
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_save(aug);
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_match(aug, "/augeas/events/saved", NULL);
+ CuAssertIntEquals(tc, 0, r);
+
+ aug_close(aug);
+}
+
int main(void) {
char *output = NULL;
CuSuite* suite = CuSuiteNew();
@@ -167,6 +199,7 @@ int main(void) {
SUITE_ADD_TEST(suite, testNoLoad);
SUITE_ADD_TEST(suite, testNoAutoload);
SUITE_ADD_TEST(suite, testInvalidLens);
+ SUITE_ADD_TEST(suite, testLoadSave);
abs_top_srcdir = getenv("abs_top_srcdir");
if (abs_top_srcdir == NULL)
More information about the augeas-devel
mailing list