database error
[notmuch-archives.git] / 49 / 595d29918e9be7bd67fe0f3c30d4e5ba33cf06
1 Return-Path: <rlb@defaultvalue.org>\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 22A70429E23\r
6         for <notmuch@notmuchmail.org>; Wed, 16 Feb 2011 18:59:14 -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 wVSl1Isu3vTC for <notmuch@notmuchmail.org>;\r
16         Wed, 16 Feb 2011 18:59:12 -0800 (PST)\r
17 Received: from defaultvalue.org (defaultvalue.org [70.85.129.156])\r
18         by olra.theworths.org (Postfix) with ESMTP id A7877431FD0\r
19         for <notmuch@notmuchmail.org>; Wed, 16 Feb 2011 18:59:12 -0800 (PST)\r
20 Received: from trouble.defaultvalue.org (localhost [127.0.0.1])\r
21         (Authenticated sender: rlb@defaultvalue.org)\r
22         by defaultvalue.org (Postfix) with ESMTPSA id B9DEC90D35\r
23         for <notmuch@notmuchmail.org>; Wed, 16 Feb 2011 20:59:23 -0600 (CST)\r
24 Received: by trouble.defaultvalue.org (Postfix, from userid 1000)\r
25         id 1BF8814E44A; Wed, 16 Feb 2011 20:59:10 -0600 (CST)\r
26 From: Rob Browning <rlb@defaultvalue.org>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: RFC: Dovecot locking\r
29 Date: Wed, 16 Feb 2011 20:59:09 -0600\r
30 Message-ID: <87zkpvv01u.fsf@trouble.defaultvalue.org>\r
31 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)\r
32 MIME-Version: 1.0\r
33 Content-Type: multipart/mixed; boundary="=-=-="\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Thu, 17 Feb 2011 02:59:14 -0000\r
47 \r
48 --=-=-=\r
49 \r
50 \r
51 This is an unfinished patch to handle Dovecot locking, which is useful\r
52 if we'd like to support running notmuch directly on a Dovecot Maildir:\r
53 \r
54   http://wiki.dovecot.org/MailboxFormat/Maildir#Locking\r
55 \r
56 For now, I'm interested in general comments, i.e. is this desirable, is\r
57 it a reasonable approach, etc.  As you can see, there's no config\r
58 handling yet, so -llockfile is added unconditionally.\r
59 \r
60 \r
61 --=-=-=\r
62 Content-Type: text/x-diff\r
63 Content-Disposition: inline; filename=tmp.diff\r
64 Content-Description: rfc-dovecot-locking.diff\r
65 \r
66 diff --git a/Makefile.local b/Makefile.local\r
67 index 38ead11..c102688 100644\r
68 --- a/Makefile.local\r
69 +++ b/Makefile.local\r
70 @@ -40,7 +40,7 @@ endif\r
71  ifeq ($(LIBDIR_IN_LDCONFIG),0)\r
72  FINAL_NOTMUCH_LDFLAGS += $(RPATH_LDFLAGS)\r
73  endif\r
74 -FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS)\r
75 +FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS) -llockfile\r
76  \r
77  .PHONY: all\r
78  all: notmuch notmuch-shared notmuch.1.gz\r
79 diff --git a/lib/message.cc b/lib/message.cc\r
80 index 979fad5..6a6a7a5 100644\r
81 --- a/lib/message.cc\r
82 +++ b/lib/message.cc\r
83 @@ -23,7 +23,9 @@\r
84  \r
85  #include <stdint.h>\r
86  \r
87 +#include <glib.h>\r
88  #include <gmime/gmime.h>\r
89 +#include <lockfile.h>\r
90  \r
91  struct _notmuch_message {\r
92      notmuch_database_t *notmuch;\r
93 @@ -1222,8 +1224,36 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
94         if (strcmp (filename, filename_new)) {\r
95             int err;\r
96             notmuch_status_t new_status;\r
97 +            char *msg_dir = g_path_get_dirname (filename);\r
98 +            char *maildir = g_path_get_dirname (msg_dir);\r
99 +            char *dovecot_lock = NULL;\r
100 +            char *dovecot_uidlist = talloc_asprintf (filename_new, "%s/%s",\r
101 +                                                     maildir,\r
102 +                                                     "dovecot-uidlist");\r
103 +\r
104 +            g_free (msg_dir);\r
105 +            g_free (maildir);\r
106 +            msg_dir = NULL;\r
107 +            if (access (dovecot_uidlist, F_OK) == 0) {\r
108 +                dovecot_lock = talloc_asprintf (filename_new, "%s.lock",\r
109 +                                                dovecot_uidlist);\r
110 +                if (lockfile_create (dovecot_lock, 0, 0) != L_SUCCESS) {\r
111 +                    fprintf (stderr, "Unable to lock %s\n", dovecot_lock);\r
112 +                    status = NOTMUCH_STATUS_FILE_ERROR;\r
113 +                    continue;\r
114 +                }\r
115 +            }\r
116  \r
117             err = rename (filename, filename_new);\r
118 +\r
119 +            if (dovecot_lock) {\r
120 +                if (lockfile_remove (dovecot_lock) != L_SUCCESS) {\r
121 +                    fprintf (stderr, "Unable to unlock %s: %s\n",\r
122 +                             dovecot_lock, strerror (errno));\r
123 +                    status = NOTMUCH_STATUS_FILE_ERROR;\r
124 +                }\r
125 +            }\r
126 +\r
127             if (err)\r
128                 continue;\r
129  \r
130 \r
131 --=-=-=\r
132 \r
133 \r
134 -- \r
135 Rob Browning\r
136 rlb @defaultvalue.org and @debian.org\r
137 GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4\r
138 \r
139 --=-=-=--\r