Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 22A70429E23 for ; Wed, 16 Feb 2011 18:59:14 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wVSl1Isu3vTC for ; Wed, 16 Feb 2011 18:59:12 -0800 (PST) Received: from defaultvalue.org (defaultvalue.org [70.85.129.156]) by olra.theworths.org (Postfix) with ESMTP id A7877431FD0 for ; Wed, 16 Feb 2011 18:59:12 -0800 (PST) Received: from trouble.defaultvalue.org (localhost [127.0.0.1]) (Authenticated sender: rlb@defaultvalue.org) by defaultvalue.org (Postfix) with ESMTPSA id B9DEC90D35 for ; Wed, 16 Feb 2011 20:59:23 -0600 (CST) Received: by trouble.defaultvalue.org (Postfix, from userid 1000) id 1BF8814E44A; Wed, 16 Feb 2011 20:59:10 -0600 (CST) From: Rob Browning To: notmuch@notmuchmail.org Subject: RFC: Dovecot locking Date: Wed, 16 Feb 2011 20:59:09 -0600 Message-ID: <87zkpvv01u.fsf@trouble.defaultvalue.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Feb 2011 02:59:14 -0000 --=-=-= This is an unfinished patch to handle Dovecot locking, which is useful if we'd like to support running notmuch directly on a Dovecot Maildir: http://wiki.dovecot.org/MailboxFormat/Maildir#Locking For now, I'm interested in general comments, i.e. is this desirable, is it a reasonable approach, etc. As you can see, there's no config handling yet, so -llockfile is added unconditionally. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tmp.diff Content-Description: rfc-dovecot-locking.diff diff --git a/Makefile.local b/Makefile.local index 38ead11..c102688 100644 --- a/Makefile.local +++ b/Makefile.local @@ -40,7 +40,7 @@ endif ifeq ($(LIBDIR_IN_LDCONFIG),0) FINAL_NOTMUCH_LDFLAGS += $(RPATH_LDFLAGS) endif -FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS) +FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS) -llockfile .PHONY: all all: notmuch notmuch-shared notmuch.1.gz diff --git a/lib/message.cc b/lib/message.cc index 979fad5..6a6a7a5 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -23,7 +23,9 @@ #include +#include #include +#include struct _notmuch_message { notmuch_database_t *notmuch; @@ -1222,8 +1224,36 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message) if (strcmp (filename, filename_new)) { int err; notmuch_status_t new_status; + char *msg_dir = g_path_get_dirname (filename); + char *maildir = g_path_get_dirname (msg_dir); + char *dovecot_lock = NULL; + char *dovecot_uidlist = talloc_asprintf (filename_new, "%s/%s", + maildir, + "dovecot-uidlist"); + + g_free (msg_dir); + g_free (maildir); + msg_dir = NULL; + if (access (dovecot_uidlist, F_OK) == 0) { + dovecot_lock = talloc_asprintf (filename_new, "%s.lock", + dovecot_uidlist); + if (lockfile_create (dovecot_lock, 0, 0) != L_SUCCESS) { + fprintf (stderr, "Unable to lock %s\n", dovecot_lock); + status = NOTMUCH_STATUS_FILE_ERROR; + continue; + } + } err = rename (filename, filename_new); + + if (dovecot_lock) { + if (lockfile_remove (dovecot_lock) != L_SUCCESS) { + fprintf (stderr, "Unable to unlock %s: %s\n", + dovecot_lock, strerror (errno)); + status = NOTMUCH_STATUS_FILE_ERROR; + } + } + if (err) continue; --=-=-= -- Rob Browning rlb @defaultvalue.org and @debian.org GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 --=-=-=--