Blame SOURCES/0022-src-augeas.c-unlink_removed_files-ensure-aug_save-re.patch

ab36df
From 4d69d88f20a7aa87d81004db44c1094ad1afea80 Mon Sep 17 00:00:00 2001
ab36df
From: Dominic Cleal <dcleal@redhat.com>
ab36df
Date: Thu, 4 Sep 2014 08:44:20 +0100
ab36df
Subject: [PATCH] * src/augeas.c (unlink_removed_files): ensure aug_save
ab36df
 returns non-zero result   when unable to delete files
ab36df
ab36df
Fixes RHBZ#1091143
ab36df
ab36df
(cherry picked from commit b61a78d2e629e4f1395270a1ee72876e27b12990)
ab36df
ab36df
Conflicts:
ab36df
	NEWS
ab36df
---
ab36df
 src/augeas.c      |  3 ++-
ab36df
 tests/test-save.c | 26 ++++++++++++++++++++++++++
ab36df
 2 files changed, 28 insertions(+), 1 deletion(-)
ab36df
ab36df
diff --git a/src/augeas.c b/src/augeas.c
ab36df
index 3c12443..014e145 100644
ab36df
--- a/src/augeas.c
ab36df
+++ b/src/augeas.c
ab36df
@@ -1488,7 +1488,8 @@ static int unlink_removed_files(struct augeas *aug,
ab36df
             for (struct tree *t = pathx_first(px);
ab36df
                  t != NULL;
ab36df
                  t = pathx_next(px)) {
ab36df
-                remove_file(aug, t);
ab36df
+                if (remove_file(aug, t) < 0)
ab36df
+                    result = -1;
ab36df
             }
ab36df
             free_pathx(px);
ab36df
         } else if (tf->dirty && ! tree_child(tm, "path")) {
ab36df
diff --git a/tests/test-save.c b/tests/test-save.c
ab36df
index f28f626..1dac75d 100644
ab36df
--- a/tests/test-save.c
ab36df
+++ b/tests/test-save.c
ab36df
@@ -29,6 +29,7 @@
ab36df
 #include <sys/stat.h>
ab36df
 #include <sys/types.h>
ab36df
 #include <sys/wait.h>
ab36df
+#include <unistd.h>
ab36df
 
ab36df
 const char *abs_top_srcdir;
ab36df
 const char *abs_top_builddir;
ab36df
@@ -70,6 +71,30 @@ static void teardown(ATTRIBUTE_UNUSED CuTest *tc) {
ab36df
     root = NULL;
ab36df
 }
ab36df
 
ab36df
+static void testRemoveNoPermission(CuTest *tc) {
ab36df
+    if (getuid() == 0) {
ab36df
+        puts("pending (testRemoveNoPermission): can't test permissions under root account");
ab36df
+        return;
ab36df
+    }
ab36df
+
ab36df
+    int r;
ab36df
+    const char *errmsg;
ab36df
+
ab36df
+    // Prevent deletion of files
ab36df
+    run(tc, "chmod 0500 %s/etc", root);
ab36df
+
ab36df
+    r = aug_rm(aug, "/files/etc/hosts");
ab36df
+    CuAssertTrue(tc, r > 0);
ab36df
+
ab36df
+    r = aug_save(aug);
ab36df
+    CuAssertIntEquals(tc, -1, r);
ab36df
+
ab36df
+    r = aug_get(aug, "/augeas/files/etc/hosts/error", &errmsg);
ab36df
+    CuAssertIntEquals(tc, 1, r);
ab36df
+    CuAssertPtrNotNull(tc, errmsg);
ab36df
+    CuAssertStrEquals(tc, "unlink_orig", errmsg);
ab36df
+}
ab36df
+
ab36df
 static void testSaveNewFile(CuTest *tc) {
ab36df
     int r;
ab36df
 
ab36df
@@ -285,6 +310,7 @@ int main(void) {
ab36df
     CuSuiteSetup(suite, setup, teardown);
ab36df
 
ab36df
     SUITE_ADD_TEST(suite, testSaveNewFile);
ab36df
+    SUITE_ADD_TEST(suite, testRemoveNoPermission);
ab36df
     SUITE_ADD_TEST(suite, testNonExistentLens);
ab36df
     SUITE_ADD_TEST(suite, testMultipleXfm);
ab36df
     SUITE_ADD_TEST(suite, testMtime);