[PATCH v2 5/5] compact: provide user more information on after-compaction failures
[notmuch-archives.git] / 7a / 9ecdaa86614b3d4bb3b84ef8da1f05269dcf8b
1 Return-Path: <too@guru-group.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 2B79D431FC7\r
6         for <notmuch@notmuchmail.org>; Wed, 13 Nov 2013 09:03:15 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id E0Y5XYJDHiFF for <notmuch@notmuchmail.org>;\r
16         Wed, 13 Nov 2013 09:03:09 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id C180F431FDB\r
19         for <notmuch@notmuchmail.org>; Wed, 13 Nov 2013 09:02:57 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 7E9A51000F3; Wed, 13 Nov 2013 19:02:53 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH v2 5/5] compact: provide user more information on\r
25         after-compaction failures\r
26 Date: Wed, 13 Nov 2013 19:02:47 +0200\r
27 Message-Id: <1384362167-12740-6-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 1.8.0\r
29 In-Reply-To: <1384362167-12740-1-git-send-email-tomi.ollila@iki.fi>\r
30 References: <1384362167-12740-1-git-send-email-tomi.ollila@iki.fi>\r
31 Cc: tomi.ollila@iki.fi\r
32 X-BeenThere: notmuch@notmuchmail.org\r
33 X-Mailman-Version: 2.1.13\r
34 Precedence: list\r
35 List-Id: "Use and development of the notmuch mail system."\r
36         <notmuch.notmuchmail.org>\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
40 List-Post: <mailto:notmuch@notmuchmail.org>\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
44 X-List-Received-Date: Wed, 13 Nov 2013 17:03:15 -0000\r
45 \r
46 After database has been compacted, there are steps to put the new\r
47 database into place -- and these steps may fail. In case such\r
48 failure happens, provide better information how to resolve it.\r
49 \r
50 Thanks to Ben Gamari for most of the information content.\r
51 ---\r
52  lib/database.cc | 39 +++++++++++++++++++++++++++++++++++----\r
53  1 file changed, 35 insertions(+), 4 deletions(-)\r
54 \r
55 diff --git a/lib/database.cc b/lib/database.cc\r
56 index 4b5ac64..a6daac6 100644\r
57 --- a/lib/database.cc\r
58 +++ b/lib/database.cc\r
59 @@ -939,19 +939,50 @@ notmuch_database_compact (const char *path,\r
60      }\r
61  \r
62      if (rename (xapian_path, backup_path)) {\r
63 -       fprintf (stderr, "Error moving old database out of the way\n");\r
64 +       fprintf (stderr, "Error moving old database out of the way:\n"\r
65 +                "Old database: %s\n"\r
66 +                "Backup database: %s\n"\r
67 +                "Error: %s\n", xapian_path, backup_path, strerror (errno));\r
68         ret = NOTMUCH_STATUS_FILE_ERROR;\r
69         goto DONE;\r
70      }\r
71  \r
72      if (rename (compact_xapian_path, xapian_path)) {\r
73 -       fprintf (stderr, "Error moving compacted database\n");\r
74 +       fprintf (stderr, "Error moving compacted database into place: %s\n",\r
75 +                strerror (errno));\r
76 +       fprintf (stderr, "\n"\r
77 +                "Encountered error while moving the compacted database\n"\r
78 +                "\n"\r
79 +                "    %s\n"\r
80 +                "\n"\r
81 +                "to\n"\r
82 +                "\n"\r
83 +                "    %s\n"\r
84 +                "\n"\r
85 +                "Please identify the reason for this and move the compacted database\n"\r
86 +                "into place manually.\n"\r
87 +                "\n"\r
88 +                "Alternatively you can revert to the uncompacted database with\n"\r
89 +                "\n"\r
90 +                "    mv '%s' '%s'\n"\r
91 +                "\n", compact_xapian_path, xapian_path,\r
92 +                backup_path, xapian_path);\r
93         ret = NOTMUCH_STATUS_FILE_ERROR;\r
94         goto DONE;\r
95      }\r
96  \r
97 -    if (! keep_backup)\r
98 -       rmtree (backup_path);\r
99 +    if (! keep_backup) {\r
100 +       if (rmtree (backup_path)) {\r
101 +           fprintf (stderr, "Error removing backup database: %s\n",\r
102 +                    strerror (errno));\r
103 +           fprintf (stderr, "\n"\r
104 +                    "Please remove the backup database with\n"\r
105 +                    "\n"\r
106 +                    "   rm -rf '%s'\n" "\n", backup_path);\r
107 +           ret = NOTMUCH_STATUS_FILE_ERROR;\r
108 +           goto DONE;\r
109 +       }\r
110 +    }\r
111  \r
112    DONE:\r
113      if (notmuch)\r
114 -- \r
115 1.8.3.1\r
116 \r