Re: [PATCH] Fix typo in Message.maildir_flags_to_tags
[notmuch-archives.git] / fa / 4121bba3a5f5829b95f72332dbf83a8e578605
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 12EA0431FBD\r
6         for <notmuch@notmuchmail.org>; Thu, 14 Nov 2013 14:03:51 -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 wZVNZu7GG1zu for <notmuch@notmuchmail.org>;\r
16         Thu, 14 Nov 2013 14:03:43 -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 8C604431FDD\r
19         for <notmuch@notmuchmail.org>; Thu, 14 Nov 2013 14:03:36 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 17D9310009D; Fri, 15 Nov 2013 00:03:29 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH v3 3/5] compact: preserve backup database until compacted\r
25         database is in place\r
26 Date: Fri, 15 Nov 2013 00:03:25 +0200\r
27 Message-Id: <1384466607-28298-1-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 1.8.0\r
29 In-Reply-To: <id:1384362167-12740-1-git-send-email-tomi.ollila@iki.fi>\r
30 References: <id: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: Thu, 14 Nov 2013 22:03:51 -0000\r
45 \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
50 ---\r
51 \r
52 The patches 3-5 in this series are updated based on Jani's comments.\r
53 \r
54 I've kept the fprintf(stderr,...)'s due to reasons explained in\r
55 \r
56 id:m28uwquccd.fsf@guru.guru-group.fi\r
57 \r
58 Diff v2-v3 for first (3/5) patch. Second (4/5) has just // -> /* .. */ change.\r
59 \r
60 |--- a/lib/database.cc\r
61 |+++ b/lib/database.cc\r
62 |@@ -906,17 +906,19 @@ notmuch_database_compact (const char *path,\r
63 |        }\r
64 |        keep_backup = FALSE;\r
65 |     }\r
66 |-    else\r
67 |+    else {\r
68 |        keep_backup = TRUE;\r
69 |+    }\r
70 |\r
71 |     if (stat (backup_path, &statbuf) != -1) {\r
72 |-       fprintf (stderr, "Backup path already exists: %s\n", backup_path);\r
73 |+       fprintf (stderr, "Path already exists: %s\n", backup_path);\r
74 |        ret = NOTMUCH_STATUS_FILE_ERROR;\r
75 |        goto DONE;\r
76 |     }\r
77 |     if (errno != ENOENT) {\r
78 |-       fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",\r
79 |+       fprintf (stderr, "Unknown error while stat()ing path: %s\n",\r
80 |                 strerror (errno));\r
81 |+       ret = NOTMUCH_STATUS_FILE_ERROR;\r
82 |        goto DONE;\r
83 |     }\r
84 \r
85 \r
86 \r
87 \r
88  lib/database.cc | 44 +++++++++++++++++++++++++++-----------------\r
89  1 file changed, 27 insertions(+), 17 deletions(-)\r
90 \r
91 diff --git a/lib/database.cc b/lib/database.cc\r
92 index 3530cb6..d79cc30 100644\r
93 --- a/lib/database.cc\r
94 +++ b/lib/database.cc\r
95 @@ -873,6 +873,7 @@ notmuch_database_compact (const char *path,\r
96      notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
97      notmuch_database_t *notmuch = NULL;\r
98      struct stat statbuf;\r
99 +    notmuch_bool_t keep_backup;\r
100  \r
101      local = talloc_new (NULL);\r
102      if (! local)\r
103 @@ -898,17 +899,27 @@ notmuch_database_compact (const char *path,\r
104         goto DONE;\r
105      }\r
106  \r
107 -    if (backup_path != NULL) {\r
108 -       if (stat (backup_path, &statbuf) != -1) {\r
109 -           fprintf (stderr, "Backup path already exists: %s\n", backup_path);\r
110 -           ret = NOTMUCH_STATUS_FILE_ERROR;\r
111 -           goto DONE;\r
112 -       }\r
113 -       if (errno != ENOENT) {\r
114 -           fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",\r
115 -                    strerror (errno));\r
116 +    if (backup_path == NULL) {\r
117 +       if (! (backup_path = talloc_asprintf (local, "%s.old", xapian_path))) {\r
118 +           ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
119             goto DONE;\r
120         }\r
121 +       keep_backup = FALSE;\r
122 +    }\r
123 +    else {\r
124 +       keep_backup = TRUE;\r
125 +    }\r
126 +\r
127 +    if (stat (backup_path, &statbuf) != -1) {\r
128 +       fprintf (stderr, "Path already exists: %s\n", backup_path);\r
129 +       ret = NOTMUCH_STATUS_FILE_ERROR;\r
130 +       goto DONE;\r
131 +    }\r
132 +    if (errno != ENOENT) {\r
133 +       fprintf (stderr, "Unknown error while stat()ing path: %s\n",\r
134 +                strerror (errno));\r
135 +       ret = NOTMUCH_STATUS_FILE_ERROR;\r
136 +       goto DONE;\r
137      }\r
138  \r
139      try {\r
140 @@ -924,14 +935,10 @@ notmuch_database_compact (const char *path,\r
141         goto DONE;\r
142      }\r
143  \r
144 -    if (backup_path) {\r
145 -       if (rename (xapian_path, backup_path)) {\r
146 -           fprintf (stderr, "Error moving old database out of the way\n");\r
147 -           ret = NOTMUCH_STATUS_FILE_ERROR;\r
148 -           goto DONE;\r
149 -       }\r
150 -    } else {\r
151 -       rmtree (xapian_path);\r
152 +    if (rename (xapian_path, backup_path)) {\r
153 +       fprintf (stderr, "Error moving old database out of the way\n");\r
154 +       ret = NOTMUCH_STATUS_FILE_ERROR;\r
155 +       goto DONE;\r
156      }\r
157  \r
158      if (rename (compact_xapian_path, xapian_path)) {\r
159 @@ -940,6 +947,9 @@ notmuch_database_compact (const char *path,\r
160         goto DONE;\r
161      }\r
162  \r
163 +    if (! keep_backup)\r
164 +       rmtree (backup_path);\r
165 +\r
166    DONE:\r
167      if (notmuch)\r
168         notmuch_database_destroy (notmuch);\r
169 -- \r
170 1.8.0\r
171 \r