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.
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 <stdint.h> +#include <glib.h> #include <gmime/gmime.h> +#include <lockfile.h> 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
_______________________________________________ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch