On Wed, 2010-09-15 at 18:53 +0200, martin f krafft wrote: > also sprach David Lutterkort <lut...@redhat.com> [2010.09.15.1756 +0200]: > > To catch your use case in all generality, I could just write the > > changed file to a memstream, do the compare from that, and only > > write to .augnew when something has changed. > > Except that will break for large files (however unlikely that ma > be).
Attached is a simple patch that I just committed upstream so that doing a 'set /foo bar' will not cause any file I/O when /foo already has the value bar. For the bigger issue of writing to memory first, and then to .augnew, I am still on the fence of whether that is a good idea (and isn't so great for large files, though there are other things in Augeas which will consume considerable amounts of memory on large files) David
>From 3ef65496495d228751a0898299c2398b7de9baf4 Mon Sep 17 00:00:00 2001 From: David Lutterkort <lut...@redhat.com> Date: Wed, 15 Sep 2010 16:39:08 -0700 Subject: [PATCH] When setting a tree node to the value it already has, do not modify the tree --- src/augeas.c | 7 +++++++ tests/test-save.c | 2 +- 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/augeas.c b/src/augeas.c index d2ef353..25ca016 100644 --- a/src/augeas.c +++ b/src/augeas.c @@ -157,6 +157,11 @@ struct tree *tree_find_cr(struct augeas *aug, const char *path) { } void tree_store_value(struct tree *tree, char **value) { + if (streqv(tree->value, *value)) { + free(*value); + *value = NULL; + return; + } if (tree->value != NULL) { free(tree->value); tree->value = NULL; @@ -171,6 +176,8 @@ void tree_store_value(struct tree *tree, char **value) { int tree_set_value(struct tree *tree, const char *value) { char *v = NULL; + if (streqv(tree->value, value)) + return 0; if (value != NULL) { v = strdup(value); if (v == NULL) diff --git a/tests/test-save.c b/tests/test-save.c index 673a5a1..68b7736 100644 --- a/tests/test-save.c +++ b/tests/test-save.c @@ -112,7 +112,7 @@ static void testMultipleXfm(CuTest *tc) { r = aug_set(aug, "/augeas/load/Yum2/incl", "/etc/yum.repos.d/*"); CuAssertIntEquals(tc, 0, r); - r = aug_set(aug, "/files/etc/yum.repos.d/fedora.repo/fedora/enabled", "1"); + r = aug_set(aug, "/files/etc/yum.repos.d/fedora.repo/fedora/enabled", "0"); CuAssertIntEquals(tc, 0, r); r = aug_save(aug); -- 1.7.2.3