[augeas-devel] [PATCH] aug_save: report saved files in /augeas/events/saved

David Lutterkort lutter at redhat.com
Tue Oct 21 18:52:12 UTC 2008


aug_save now reports which files were changed on disk underneath
/augeas/events/saved; if multiple files are changed in one save operation,
there will be multiple /augeas/events/saved entries in the tree. The value
of each is the path to the file prefixed with /files.
---
 src/augeas.c               |   19 +++++++++++++++++--
 src/internal.h             |    6 ++++++
 tests/Makefile.am          |    3 ++-
 tests/test-events-saved.sh |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 3 deletions(-)
 create mode 100755 tests/test-events-saved.sh

diff --git a/src/augeas.c b/src/augeas.c
index 1099666..2a5f7bf 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -897,9 +897,11 @@ static int tree_save(struct augeas *aug, struct tree *tree, const char *path,
                      int *count) {
     int result = 0;
     // FIXME: We need to detect subtrees that aren't saved by anything
+    aug_rm(aug, AUGEAS_EVENTS_SAVED);
+
     list_for_each(t, tree) {
         if (t->dirty) {
-            char *tpath;
+            char *tpath = NULL;
             struct transform *transform = NULL;
             if (asprintf(&tpath, "%s/%s", path, t->label) == -1) {
                 result = -1;
@@ -922,8 +924,21 @@ static int tree_save(struct augeas *aug, struct tree *tree, const char *path,
                 int r = transform_save(aug, transform, tpath, t);
                 if (r == -1)
                     result = -1;
-                else if (r > 0)
+                else if (r > 0) {
+                    char *sp;
                     *count += 1;
+                    if (asprintf(&sp, AUGEAS_EVENTS_SAVED "[%d]",
+                                 *count) < 0) {
+                        free(tpath);
+                        return -1;
+                    }
+                    if (aug_set(aug, sp, tpath) < 0) {
+                        free(tpath);
+                        free(sp);
+                        return -1;
+                    }
+                    free(sp);
+                }
             } else {
                 if (tree_save(aug, t->children, tpath, count) == -1)
                     result = -1;
diff --git a/src/internal.h b/src/internal.h
index 53c6dee..0334d8a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -69,6 +69,12 @@
  * How we save files. One of 'backup', 'overwrite' or 'newfile' */
 #define AUGEAS_META_SAVE_MODE AUGEAS_META_TREE "/save"
 
+/* A hierarchy where we record certain 'events', e.g. which tree
+ * nodes actually gotsaved into files */
+#define AUGEAS_EVENTS AUGEAS_META_TREE "/events"
+
+#define AUGEAS_EVENTS_SAVED AUGEAS_EVENTS "/saved"
+
 /* Define: AUGEAS_LENS_ENV
  * Name of env var that contains list of paths to search for additional
    spec files */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a9e9f9b..b23b05c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,7 +11,8 @@ valgrind: fatest
 
 check_SCRIPTS=test-lenses.sh test-interpreter.sh test-get.sh \
               test-put-symlink.sh test-save-empty.sh test-mv.sh \
-              test-bug-1.sh test-idempotent.sh test-preserve.sh
+              test-bug-1.sh test-idempotent.sh test-preserve.sh \
+	      test-events-saved.sh
 
 EXTRA_DIST=augtest $(AUGTESTS) root \
 	   $(check_SCRIPTS) $(wildcard modules/*.aug)
diff --git a/tests/test-events-saved.sh b/tests/test-events-saved.sh
new file mode 100755
index 0000000..97c1714
--- /dev/null
+++ b/tests/test-events-saved.sh
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+# Check that saving preserves mode and ownership; for this test to make
+# much sense (if any) the user running it should have at least one
+# supplementary group
+
+run_augtool() {
+augtool --nostdinc -r $root -I $abs_top_srcdir/lenses <<EOF
+set /files/etc/hosts/1/ipaddr 127.0.1.1
+set /files/etc/grub.conf/default 3
+set /files/etc/inittab/1/action fake
+save
+match /augeas/events/saved
+EOF
+}
+
+root=$abs_top_builddir/build/test-events-saved
+
+rm -rf $root
+mkdir -p $root/etc
+
+for f in hosts grub.conf inittab; do
+  cp -p $abs_top_srcdir/tests/root/etc/$f $root/etc
+done
+
+saved=$(run_augtool | grep ^/augeas/events/saved | cut -d ' ' -f 3 | tr '\n' ' ')
+exp="/files/etc/grub.conf /files/etc/hosts /files/etc/inittab "
+
+if [ "$saved" != "$exp" ]
+then
+    echo "Unexpected entries in /augeas/events/saved:"
+    echo "$exp"
+    exit 1
+fi
-- 
1.5.5.1




More information about the augeas-devel mailing list