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 04F87431E82
\r
6 for <notmuch@notmuchmail.org>; Wed, 13 Nov 2013 09:03:03 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 cI-b-5us4uYx for <notmuch@notmuchmail.org>;
\r
16 Wed, 13 Nov 2013 09:02:56 -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 6D264431FD0
\r
19 for <notmuch@notmuchmail.org>; Wed, 13 Nov 2013 09:02:56 -0800 (PST)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 15DDD1000F3; Wed, 13 Nov 2013 19:02:52 +0200 (EET)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH v2 3/5] compact: preserve backup database until compacted
\r
25 database is in place
\r
26 Date: Wed, 13 Nov 2013 19:02:45 +0200
\r
27 Message-Id: <1384362167-12740-4-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
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:03 -0000
\r
46 It is less error prone and window of failure opportunity is smaller
\r
47 if the old (backup) database is always renamed (instead of sometimes
\r
48 rmtree'd) before new (compacted) database is put into its place.
\r
49 Finally rmtree() old database in case old database backup is not kept.
\r
51 lib/database.cc | 42 +++++++++++++++++++++++++-----------------
\r
52 1 file changed, 25 insertions(+), 17 deletions(-)
\r
54 diff --git a/lib/database.cc b/lib/database.cc
\r
55 index 3530cb6..ee09c5e 100644
\r
56 --- a/lib/database.cc
\r
57 +++ b/lib/database.cc
\r
58 @@ -873,6 +873,7 @@ notmuch_database_compact (const char *path,
\r
59 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
60 notmuch_database_t *notmuch = NULL;
\r
61 struct stat statbuf;
\r
62 + notmuch_bool_t keep_backup;
\r
64 local = talloc_new (NULL);
\r
66 @@ -898,17 +899,25 @@ notmuch_database_compact (const char *path,
\r
70 - if (backup_path != NULL) {
\r
71 - if (stat (backup_path, &statbuf) != -1) {
\r
72 - fprintf (stderr, "Backup path already exists: %s\n", backup_path);
\r
73 - ret = NOTMUCH_STATUS_FILE_ERROR;
\r
76 - if (errno != ENOENT) {
\r
77 - fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",
\r
78 - strerror (errno));
\r
79 + if (backup_path == NULL) {
\r
80 + if (! (backup_path = talloc_asprintf (local, "%s.old", xapian_path))) {
\r
81 + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
84 + keep_backup = FALSE;
\r
87 + keep_backup = TRUE;
\r
89 + if (stat (backup_path, &statbuf) != -1) {
\r
90 + fprintf (stderr, "Backup path already exists: %s\n", backup_path);
\r
91 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
94 + if (errno != ENOENT) {
\r
95 + fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",
\r
96 + strerror (errno));
\r
101 @@ -924,14 +933,10 @@ notmuch_database_compact (const char *path,
\r
105 - if (backup_path) {
\r
106 - if (rename (xapian_path, backup_path)) {
\r
107 - fprintf (stderr, "Error moving old database out of the way\n");
\r
108 - ret = NOTMUCH_STATUS_FILE_ERROR;
\r
112 - rmtree (xapian_path);
\r
113 + if (rename (xapian_path, backup_path)) {
\r
114 + fprintf (stderr, "Error moving old database out of the way\n");
\r
115 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
119 if (rename (compact_xapian_path, xapian_path)) {
\r
120 @@ -940,6 +945,9 @@ notmuch_database_compact (const char *path,
\r
124 + if (! keep_backup)
\r
125 + rmtree (backup_path);
\r
129 notmuch_database_destroy (notmuch);
\r