[augeas-devel] [PATCH] aug_mv: fix bug when moving at the root level

David Lutterkort dlutter at redhat.com
Fri Aug 15 04:30:37 UTC 2008


2 files changed, 16 insertions(+), 8 deletions(-)
src/augeas.c     |    8 ++++++--
tests/test-mv.sh |   16 ++++++++++------


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1218774572 25200
# Node ID 5c6c8a65b18cece7457827cd6b9ab5b62bf8c707
# Parent  f4d5525d3f0341755e07c99ac63c71e42120b250
aug_mv: fix bug when moving at the root level

When moving from the root level, the source node needs to be removed from
aug->tree, not aug->tree->children. In addition, the list_removemacro must
be passed aug->tree and not a local variable holding that value, since we
might have to remove the list entry that aug->tree is pointing to.

Added test in test-mv.sh to test that moving at the root level works.

diff -r f4d5525d3f03 -r 5c6c8a65b18c src/augeas.c
--- a/src/augeas.c	Thu Aug 14 17:14:51 2008 -0700
+++ b/src/augeas.c	Thu Aug 14 21:29:32 2008 -0700
@@ -814,8 +814,12 @@
 
 
     t = seg_parent(s, last_segment(s));
-    if (t == NULL) t = root;
-    list_remove(ts, t->children);
+    if (t == NULL) {
+        list_remove(ts, aug->tree);
+        t = aug->tree;
+    } else {
+        list_remove(ts, t->children);
+    }
 
     t->dirty = 1;
     td->dirty = 1;
diff -r f4d5525d3f03 -r 5c6c8a65b18c tests/test-mv.sh
--- a/tests/test-mv.sh	Thu Aug 14 17:14:51 2008 -0700
+++ b/tests/test-mv.sh	Thu Aug 14 21:29:32 2008 -0700
@@ -3,7 +3,7 @@
 aug_mv() {
 (augtool -r /dev/null | grep -v '/augeas\|augtool' | tr '\n' ' ') <<EOF
 set /a/b/c value
-mv /a/b/c $1
+mv $1 $2
 print
 EOF
 }
@@ -19,23 +19,27 @@
 
 }
 
-ACT=$(aug_mv /x)
+ACT=$(aug_mv /a/b/c /x)
 EXP='/a /a/b /x = "value" '
 assert_eq /x
 
-ACT=$(aug_mv /x/y)
+ACT=$(aug_mv /a/b/c /x/y)
 EXP='/a /a/b /x /x/y = "value" '
 assert_eq /x/y
 
-ACT=$(aug_mv /a/x)
+ACT=$(aug_mv /a/b/c /a/x)
 EXP='/a /a/b /a/x = "value" '
 assert_eq /a/x
 
 # Check that we don't move into a descendant
-ACT=$(aug_mv /a/b/c/d)
+ACT=$(aug_mv /a/b/c /a/b/c/d)
 EXP='Failed /a /a/b /a/b/c = "value" /a/b/c/d '
 assert_eq /a/b/c/d
 
-ACT=$(aug_mv /a/b/d)
+ACT=$(aug_mv /a/b/c /a/b/d)
 EXP='/a /a/b /a/b/d = "value" '
 assert_eq /a/b/d
+
+ACT=$(aug_mv /a /x/y)
+EXP='/x /x/y /x/y/b /x/y/b/c = "value" '
+assert_eq "/a to /x/y"




More information about the augeas-devel mailing list