[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - Do not delete files that had an error upon parsing



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=24fd141bffaea4dd5cc1a8e9d62d9452431731d7
Commit:        24fd141bffaea4dd5cc1a8e9d62d9452431731d7
Parent:        835e50a424eb1ca40c289e864e121538abb29329
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Fri Mar 6 14:53:54 2009 -0800
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Fri Mar 6 15:04:58 2009 -0800

Do not delete files that had an error upon parsing

When we can't read a file, we create an entry for it under /augeas, but
there won't be anything for it under /files. That looks a lot like a file
whose entire subtree was deleted; but since we failed reading the file, we
should not delete it either.
---
 src/augeas.c               |    9 ++++++++-
 tests/Makefile.am          |    2 +-
 tests/test-unlink-error.sh |   24 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index 718fb00..ba05d66 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -634,6 +634,13 @@ static struct tree *tree_child(struct tree *tree, const char *label) {
 
 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
+     * unlinked. A node corresponds to a file if it has a child labelled
+     * 'path', and we only consider it if there are no errors associated
+     * with it */
+    static const char *const file_nodes =
+        "descendant-or-self::*[path][count(error) = 0]";
+
     int result = 0;
 
     if (! files->dirty)
@@ -645,7 +652,7 @@ static int unlink_removed_files(struct augeas *aug,
         if (tf == NULL) {
             /* Unlink all files in tm */
             struct pathx *px = NULL;
-            if (pathx_parse(tm, "descendant-or-self::*[path]", &px)
+            if (pathx_parse(tm, file_nodes, &px)
                 != PATHX_NOERROR) {
                 result = -1;
                 continue;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 20229c8..023e840 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -12,7 +12,7 @@ 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-events-saved.sh test-save-mode.sh
+	      test-events-saved.sh test-save-mode.sh test-unlink-error.sh
 
 EXTRA_DIST=augtest $(AUGTESTS) root \
 	   $(check_SCRIPTS) $(wildcard modules/*.aug) xpath.tests
diff --git a/tests/test-unlink-error.sh b/tests/test-unlink-error.sh
new file mode 100755
index 0000000..350e7ca
--- /dev/null
+++ b/tests/test-unlink-error.sh
@@ -0,0 +1,24 @@
+#! /bin/bash
+
+# Make sure we don't delete files simply because there was an error reading
+# them in
+
+root=$abs_top_builddir/build/test-unlink-error
+xinetd=$root/etc/xinetd.conf
+
+rm -rf $root
+mkdir -p $(dirname $xinetd)
+
+cat > $xinetd <<EOF
+intentional garbage
+EOF
+
+augtool --nostdinc -r $root -I $abs_top_srcdir/lenses > /dev/null <<EOF
+clear /files
+save
+EOF
+
+if [ ! -f $xinetd ] ; then
+  echo "Deleted xinetd.conf"
+  exit 1
+fi



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]