From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id DD0F5431E62 for ; Mon, 10 Dec 2012 22:55:40 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 KWajkUoXeqYW for ; Mon, 10 Dec 2012 22:55:38 -0800 (PST) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 43F41431FBD for ; Mon, 10 Dec 2012 22:55:35 -0800 (PST) Received: by mail-pa0-f53.google.com with SMTP id hz1so2441344pad.26 for ; Mon, 10 Dec 2012 22:55:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=fFHCugg9BZ3Fa8/VqMQ+ulpnCigvY1hBCSaocgGH6PI=; b=nz8F6L1WtFas2plH9zvUwBD69P/dNGIkce/6im69WIMamqEgKwWOZ8FgxIaOrqHgNZ Xk/+6jd2ELE2CRicOD0eZqV2mfu4+njeozDYI1RbmsXrfPpI6jObChVh78ApdsH9s5e2 Wz6lRQKhx0k3kYSk66Q9z2xnUteSZlsoQN19PSfW0YazabsPdca5me9aBcCaXVxcYzqE udzLYLbXo3i2HOZcR3GXFZ2olZAIYkqEwYuBrzYU29JocinQVj36Rb+H3Z1ni3ESKdkU QGuzuKR129s9aG0lHYm1qy3cMd9vNlXSTabmOEAglsMELVwQPcQ+lnGFiY3sqFhcQIJw hiyg== Received: by 10.68.235.71 with SMTP id uk7mr46230860pbc.10.1355208934587; Mon, 10 Dec 2012 22:55:34 -0800 (PST) Received: from localhost ([2601:9:580:4c:21f:16ff:fe34:119e]) by mx.google.com with ESMTPS id pm8sm11992599pbb.29.2012.12.10.22.55.33 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 10 Dec 2012 22:55:34 -0800 (PST) From: Michael Forney To: notmuch@notmuchmail.org Subject: [PATCH 2/2] lib: Allow synchronizing message changes with a separate database connection Date: Mon, 10 Dec 2012 22:54:53 -0800 Message-Id: <1355208893-16122-3-git-send-email-mforney@mforney.org> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1355208893-16122-1-git-send-email-mforney@mforney.org> References: <1355208893-16122-1-git-send-email-mforney@mforney.org> X-Gm-Message-State: ALoCoQk9lzXuL/ZXZHE/Jyv25ryZu7qNGGLxJVSuO8wlnrWaXQ7rJL2Yv/SWmRaSElTqziflFR20 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: Tue, 11 Dec 2012 06:55:41 -0000 The motivation for this patch is that in some cases, it is ideal to open a read-only database, and only open the database as writable when we need to make changes to a message. This way, we don't block other programs to write to the database when we don't need to. With the current system, in order to modify a tag of a message opened read-only, I would have to find the message in a writable database with my read-only message's ID, which would cause unnecessary reads from the database, and seems overly complicated for a simple operation (replace document). --- bindings/go/src/notmuch/notmuch.go | 3 ++- bindings/python/notmuch/message.py | 4 +++- lib/database.cc | 7 +++++++ lib/notmuch.h | 26 +++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go index 56eb710..85c6620 100644 --- a/bindings/go/src/notmuch/notmuch.go +++ b/bindings/go/src/notmuch/notmuch.go @@ -957,7 +957,8 @@ func (self *Message) RemoveAllTags() Status { * notmuch_message_sync (message); * * This method only works if the database associated with 'message' was - * opened in read-write mode. + * opened in read-write mode. If you wish make changes to a message + * opened with a read-only database, see notmuch_database_sync_message. * * Return value: * diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py index 600c01e..b4f2d25 100644 --- a/bindings/python/notmuch/message.py +++ b/bindings/python/notmuch/message.py @@ -420,7 +420,9 @@ class Message(Python3StringMixIn): msg.tags_to_maildir_flags() This method only works if the database associated with 'message' was - opened with NOTMUCH_DATABASE_MODE_READ_WRITE. + opened with NOTMUCH_DATABASE_MODE_READ_WRITE. If you wish make + changes to a message opened with a read-only database, see + notmuch_database_sync_message. :param sync_maildir_flags: If notmuch configuration is set to do this, add maildir flags corresponding to notmuch tags. See diff --git a/lib/database.cc b/lib/database.cc index 98ea789..a9718ab 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -388,6 +388,13 @@ notmuch_database_find_message (notmuch_database_t *notmuch, } } +notmuch_status_t +notmuch_database_sync_message (notmuch_database_t *notmuch, + notmuch_message_t *message) +{ + return _notmuch_message_sync_to_database (message, notmuch); +} + /* Advance 'str' past any whitespace or RFC 822 comments. A comment is * a (potentially nested) parenthesized sequence with '\' used to * escape any character (including parentheses). diff --git a/lib/notmuch.h b/lib/notmuch.h index f6962ee..1570917 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -446,6 +446,23 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch, const char *filename, notmuch_message_t **message); +/* Synchronize the current state of 'message' into the given database. + * + * This is a more general version of notmuch_message_sync, allowing you + * to synchronize changes to a message opened with a read-only database + * into a writable database. + * + * Return value: + * + * NOTMUCH_STATUS_SUCCESS: Message successfully synchronized. + * + * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only + * mode so message cannot be modified. + */ +notmuch_status_t +notmuch_database_sync_message (notmuch_database_t *notmuch, + notmuch_message_t *message); + /* Return a list of all tags found in the database. * * This function creates a list of all tags found in the database. The @@ -1040,7 +1057,8 @@ notmuch_message_get_tags (notmuch_message_t *message); /* Add a tag to the given message. * * The changes to the message will not be committed into the database - * until notmuch_message_sync is called. + * until notmuch_message_sync or notmuch_database_sync_message is + * called. * * Return value: * @@ -1057,7 +1075,8 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag); /* Remove a tag from the given message. * * The changes to the message will not be committed into the database - * until notmuch_message_sync is called. + * until notmuch_message_sync or notmuch_database_sync_message is + * called. * * Return value: * @@ -1171,7 +1190,8 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message); * notmuch_message_sync (message); * * This method only works if the database associated with 'message' was - * opened in read-write mode. + * opened in read-write mode. If you wish make changes to a message + * opened with a read-only database, see notmuch_database_sync_message. * * Return value: * -- 1.8.0