--- /dev/null
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 18972429E4F\r
+ for <notmuch@notmuchmail.org>; Mon, 11 Nov 2013 09:56:00 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id rOWV1hIRNZL6 for <notmuch@notmuchmail.org>;\r
+ Mon, 11 Nov 2013 09:55:50 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id F0743429E31\r
+ for <notmuch@notmuchmail.org>; Mon, 11 Nov 2013 09:55:49 -0800 (PST)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id A08011000F3; Mon, 11 Nov 2013 19:55:45 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] lib: provide user more information on after-compaction\r
+ failures\r
+Date: Mon, 11 Nov 2013 19:55:38 +0200\r
+Message-Id: <1384192538-15291-4-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.8.0\r
+In-Reply-To: <1384192538-15291-1-git-send-email-tomi.ollila@iki.fi>\r
+References: <1384192538-15291-1-git-send-email-tomi.ollila@iki.fi>\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 11 Nov 2013 17:56:00 -0000\r
+\r
+After database has been compacted, there are steps to put the new\r
+database into place -- and these steps may fail. Provide better\r
+information how to resolve these failure cases.\r
+\r
+Thanks to Ben Gamari for most of the information content.\r
+---\r
+ lib/database.cc | 38 ++++++++++++++++++++++++++++++++++----\r
+ 1 file changed, 34 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 78693b7..40272dc 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -937,19 +937,49 @@ notmuch_database_compact (const char* path,\r
+ }\r
+ \r
+ if (rename(xapian_path, backup_path)) {\r
+- fprintf (stderr, "Error moving old database out of the way\n");\r
++ fprintf (stderr, "Error moving old database out of the way:\n"\r
++ "Old database: %s\n"\r
++ "Backup database: %s\n"\r
++ "Error: %s\n", xapian_path, backup_path, strerror (errno));\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (rename(compact_xapian_path, xapian_path)) {\r
+- fprintf (stderr, "Error moving compacted database\n");\r
++ fprintf (stderr, "Error moving compacted database into place: %s\n", strerror (errno));\r
++ fprintf (stderr, "\n"\r
++ "Encountered error while moving the compacted database\n"\r
++ "\n"\r
++ " %s\n"\r
++ "\n"\r
++ "to\n"\r
++ "\n"\r
++ " %s\n"\r
++ "\n"\r
++ "Please identify the reason for this and move the compacted database\n"\r
++ "into place manually.\n"\r
++ "\n"\r
++ "Alternatively you can revert to the uncompacted database with\n"\r
++ "\n"\r
++ " mv '%s' '%s'\n"\r
++ "\n", compact_xapian_path, xapian_path,\r
++ backup_path, xapian_path);\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+- if (! keep_backup)\r
+- rmtree (backup_path);\r
++ if (! keep_backup) {\r
++ if (rmtree (backup_path)) {\r
++ fprintf (stderr, "Error removing backup database: %s\n",\r
++ strerror (errno));\r
++ fprintf (stderr, "\n"\r
++ "Please remove the backup database with\n"\r
++ "\n"\r
++ " rm -rf '%s'\n" "\n", backup_path);\r
++ ret = NOTMUCH_STATUS_FILE_ERROR;\r
++ goto DONE;\r
++ }\r
++ }\r
+ \r
+ DONE:\r
+ if (notmuch)\r
+-- \r
+1.8.3.1\r
+\r