[augeas-devel] augeas: master - Produce better error message for multiple matching transforms in save

David Lutterkort lutter at fedoraproject.org
Thu Jan 7 20:40:31 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=1b55dd97290099cd15a412d3b382c25e27ff4275
Commit:        1b55dd97290099cd15a412d3b382c25e27ff4275
Parent:        745490e6af85935e4cdd6d0f1c8246f7e780a0ed
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Jan 6 11:36:33 2010 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Jan 7 11:45:04 2010 -0800

Produce better error message for multiple matching transforms in save

  * src/augeas.h (aug_errcode_t): new error code AUG_EMXFM
  * src/augeas.c (errcodes): new error string for AUG_EMXFM; (tree_save):
    report multiple transforms as proper error
  * tests/test-save.c (testMultipleXfm): new test
---
 src/augeas.c      |   15 +++++++++++++--
 src/augeas.h      |    3 ++-
 tests/test-save.c |   19 ++++++++++++++++++-
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index 2f4b788..a363f93 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -61,7 +61,8 @@ static const char *const errcodes[] = {
     "No match for path expression",                     /* AUG_ENOMATCH */
     "Too many matches for path expression",             /* AUG_EMMATCH */
     "Syntax error in lens definition",                  /* AUG_ESYNTAX */
-    "Lens not found"                                    /* AUG_ENOLENS */
+    "Lens not found",                                   /* AUG_ENOLENS */
+    "Multiple transforms"                               /* AUG_EMXFM */
 };
 
 static void tree_mark_dirty(struct tree *tree) {
@@ -921,7 +922,17 @@ static int tree_save(struct augeas *aug, struct tree *tree,
                     if (transform == NULL || transform == xfm) {
                         transform = xfm;
                     } else {
-                        FIXME("Multiple transforms for %s", path);
+                        const char *filename =
+                            tpath + strlen(AUGEAS_FILES_TREE) + 1;
+                        transform_file_error(aug, "mxfm_save", filename,
+                           "Lenses %s and %s could be used to save this file",
+                                             xfm_lens_name(transform),
+                                             xfm_lens_name(xfm));
+                        ERR_REPORT(aug, AUG_EMXFM,
+                                   "Path %s transformable by lens %s and %s",
+                                   tpath,
+                                   xfm_lens_name(transform),
+                                   xfm_lens_name(xfm));
                         result = -1;
                     }
                 }
diff --git a/src/augeas.h b/src/augeas.h
index 5481efe..514578b 100644
--- a/src/augeas.h
+++ b/src/augeas.h
@@ -284,7 +284,8 @@ typedef enum {
     AUG_ENOMATCH,       /* No match for path expression */
     AUG_EMMATCH,        /* Too many matches for path expression */
     AUG_ESYNTAX,        /* Syntax error in lens file */
-    AUG_ENOLENS         /* Lens lookup failed */
+    AUG_ENOLENS,        /* Lens lookup failed */
+    AUG_EMXFM           /* Multiple transforms */
 } aug_errcode_t;
 
 /* Return the error code from the last API call */
diff --git a/tests/test-save.c b/tests/test-save.c
index 3bef883..095dda6 100644
--- a/tests/test-save.c
+++ b/tests/test-save.c
@@ -103,7 +103,6 @@ static void testSaveNewFile(CuTest *tc) {
     CuAssertIntEquals(tc, 1, r);
 }
 
-ATTRIBUTE_UNUSED
 static void testNonExistentLens(CuTest *tc) {
     int r;
 
@@ -123,6 +122,23 @@ static void testNonExistentLens(CuTest *tc) {
     CuAssertIntEquals(tc, AUG_ENOLENS, r);
 }
 
+static void testMultipleXfm(CuTest *tc) {
+    int r;
+
+    r = aug_set(aug, "/augeas/load/Yum2/lens", "Yum.lns");
+    CuAssertIntEquals(tc, 0, r);
+    r = aug_set(aug, "/augeas/load/Yum2/incl", "/etc/yum.repos.d/*");
+    CuAssertIntEquals(tc, 0, r);
+
+    r = aug_set(aug, "/files/etc/yum.repos.d/fedora.repo/fedora/enabled", "1");
+    CuAssertIntEquals(tc, 0, r);
+
+    r = aug_save(aug);
+    CuAssertIntEquals(tc, -1, r);
+    r = aug_error(aug);
+    CuAssertIntEquals(tc, AUG_EMXFM, r);
+}
+
 int main(void) {
     char *output = NULL;
     CuSuite* suite = CuSuiteNew();
@@ -143,6 +159,7 @@ int main(void) {
 
     SUITE_ADD_TEST(suite, testSaveNewFile);
     SUITE_ADD_TEST(suite, testNonExistentLens);
+    SUITE_ADD_TEST(suite, testMultipleXfm);
 
     CuSuiteRun(suite);
     CuSuiteSummary(suite, &output);




More information about the augeas-devel mailing list