[PATCH 3/3] lib: provide user more information on after-compaction failures

Tomi Ollila tomi.ollila at iki.fi
Mon Nov 11 09:55:38 PST 2013


After database has been compacted, there are steps to put the new
database into place -- and these steps may fail. Provide better
information how to resolve these failure cases.

Thanks to Ben Gamari for most of the information content.
---
 lib/database.cc | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 78693b7..40272dc 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -937,19 +937,49 @@ notmuch_database_compact (const char* path,
     }
 
     if (rename(xapian_path, backup_path)) {
-	fprintf (stderr, "Error moving old database out of the way\n");
+	fprintf (stderr, "Error moving old database out of the way:\n"
+		 "Old database: %s\n"
+		 "Backup database: %s\n"
+		 "Error: %s\n", xapian_path, backup_path, strerror (errno));
 	ret = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
     }
 
     if (rename(compact_xapian_path, xapian_path)) {
-	fprintf (stderr, "Error moving compacted database\n");
+	fprintf (stderr, "Error moving compacted database into place: %s\n", strerror (errno));
+	fprintf (stderr, "\n"
+		 "Encountered error while moving the compacted database\n"
+		 "\n"
+		 "    %s\n"
+		 "\n"
+		 "to\n"
+		 "\n"
+		 "    %s\n"
+		 "\n"
+		 "Please identify the reason for this and move the compacted database\n"
+		 "into place manually.\n"
+		 "\n"
+		 "Alternatively you can revert to the uncompacted database with\n"
+		 "\n"
+		 "    mv '%s' '%s'\n"
+		 "\n", compact_xapian_path, xapian_path,
+		 backup_path, xapian_path);
 	ret = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
     }
 
-    if (! keep_backup)
-	rmtree (backup_path);
+    if (! keep_backup) {
+	if (rmtree (backup_path)) {
+	    fprintf (stderr, "Error removing backup database: %s\n",
+		     strerror (errno));
+	    fprintf (stderr, "\n"
+		     "Please remove the backup database with\n"
+		     "\n"
+		     "   rm -rf '%s'\n" "\n", backup_path);
+	    ret = NOTMUCH_STATUS_FILE_ERROR;
+	    goto DONE;
+	}
+    }
 
 DONE:
     if (notmuch)
-- 
1.8.3.1



More information about the notmuch mailing list