Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / e2 / b4f9365501d05eedeedb9324cad4811145debd
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 152CD431FDD\r
6         for <notmuch@notmuchmail.org>; Mon, 11 Nov 2013 09:56: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 lf1FaGgTkvmV for <notmuch@notmuchmail.org>;\r
16         Mon, 11 Nov 2013 09:56: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 5D7CC429E4E\r
19         for <notmuch@notmuchmail.org>; Mon, 11 Nov 2013 09:55:58 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id F189E1000E5; Mon, 11 Nov 2013 19:55:43 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH 1/3] lib: make compact to keep backup until new database in\r
25         place\r
26 Date: Mon, 11 Nov 2013 19:55:36 +0200\r
27 Message-Id: <1384192538-15291-2-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 1.8.0\r
29 In-Reply-To: <1384192538-15291-1-git-send-email-tomi.ollila@iki.fi>\r
30 References: <1384192538-15291-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: Mon, 11 Nov 2013 17:56:15 -0000\r
45 \r
46 It is less error prone and window of failure opportunity is smaller\r
47 if the old database is always renamed (instead of sometimes rmtree'd)\r
48 before new database is put into its place.\r
49 Finally rmtree() old database in case old database backup is not kept.\r
50 ---\r
51  lib/database.cc | 44 ++++++++++++++++++++++++++------------------\r
52  1 file changed, 26 insertions(+), 18 deletions(-)\r
53 \r
54 diff --git a/lib/database.cc b/lib/database.cc\r
55 index a021bf1..6b656e9 100644\r
56 --- a/lib/database.cc\r
57 +++ b/lib/database.cc\r
58 @@ -871,6 +871,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 +    bool keep_backup;\r
63  \r
64      local = talloc_new (NULL);\r
65      if (! local)\r
66 @@ -896,17 +897,25 @@ notmuch_database_compact (const char* path,\r
67         goto DONE;\r
68      }\r
69  \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
74 -           goto DONE;\r
75 -       }\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
82             goto DONE;\r
83         }\r
84 +       keep_backup = FALSE;\r
85 +    }\r
86 +    else\r
87 +       keep_backup = TRUE;\r
88 +\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
92 +       goto DONE;\r
93 +    }\r
94 +    if (errno != ENOENT) {\r
95 +       fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",\r
96 +                strerror(errno));\r
97 +       goto DONE;\r
98      }\r
99  \r
100      try {\r
101 @@ -922,14 +931,10 @@ notmuch_database_compact (const char* path,\r
102         goto DONE;\r
103      }\r
104  \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
109 -           goto DONE;\r
110 -       }\r
111 -    } else {\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
116 +       goto DONE;\r
117      }\r
118  \r
119      if (rename(compact_xapian_path, xapian_path)) {\r
120 @@ -938,6 +943,9 @@ notmuch_database_compact (const char* path,\r
121         goto DONE;\r
122      }\r
123  \r
124 +    if (! keep_backup)\r
125 +       rmtree (backup_path);\r
126 +\r
127  DONE:\r
128      if (notmuch)\r
129         notmuch_database_destroy (notmuch);\r
130 @@ -1538,7 +1546,7 @@ _notmuch_database_generate_doc_id (notmuch_database_t *notmuch)\r
131      notmuch->last_doc_id++;\r
132  \r
133      if (notmuch->last_doc_id == 0)\r
134 -       INTERNAL_ERROR ("Xapian document IDs are exhausted.\n");        \r
135 +       INTERNAL_ERROR ("Xapian document IDs are exhausted.\n");\r
136  \r
137      return notmuch->last_doc_id;\r
138  }\r
139 -- \r
140 1.8.3.1\r
141 \r