[augeas-devel] [PATCH] Only try to save backup file if original exists

David Lutterkort lutter at redhat.com
Wed Nov 19 13:48:04 UTC 2008


* transform.c (transform_save): check that original exists before
creating backup
---
 src/transform.c        |    2 +-
 tests/test-preserve.sh |   13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/transform.c b/src/transform.c
index 93bf485..1518356 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -600,7 +600,7 @@ int transform_save(struct augeas *aug, struct transform *xform,
     }
 
     if (!(aug->flags & AUG_SAVE_NEWFILE)) {
-        if (aug->flags & AUG_SAVE_BACKUP) {
+        if (augorig_exists && (aug->flags & AUG_SAVE_BACKUP)) {
             int r;
             r = asprintf(&augsave, "%s%s" EXT_AUGSAVE, aug->root, filename);
             if (r == -1) {
diff --git a/tests/test-preserve.sh b/tests/test-preserve.sh
index aeb2186..f975270 100755
--- a/tests/test-preserve.sh
+++ b/tests/test-preserve.sh
@@ -72,6 +72,19 @@ if [ $? != 0 ] ; then
     exit 1
 fi
 
+# Check that we create new files without error when backups are requested
+init_dirs
+
+$AUGTOOL -b > /dev/null <<EOF
+set /files/etc/hosts/1/ipaddr 127.0.0.1
+set /files/etc/hosts/1/canonical host.example.com
+save
+EOF
+if [ $? != 0 ] ; then
+    echo "augtool -b failed on new file"
+    exit 1
+fi
+
 # Check that we preserve a backup file on request
 echo -e '127.0.0.1\tlocalhost' > $hosts
 exp_inode=$(stat_inode $hosts)
-- 
1.5.6.5




More information about the augeas-devel mailing list