--- /dev/null
+Return-Path: <stebalien@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 7A7AA6DE1617\r
+ for <notmuch@notmuchmail.org>; Sun, 25 Oct 2015 14:31:02 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.647\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.647 tagged_above=-999 required=5 tests=[AWL=0.053,\r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01,\r
+ SPF_PASS=-0.001, T_FREEMAIL_FORGED_FROMDOMAIN=0.01,\r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id P4N5WUghiR8j for <notmuch@notmuchmail.org>;\r
+ Sun, 25 Oct 2015 14:31:00 -0700 (PDT)\r
+Received: from mail-yk0-f180.google.com (mail-yk0-f180.google.com\r
+ [209.85.160.180])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id EF4086DE15DC\r
+ for <notmuch@notmuchmail.org>; Sun, 25 Oct 2015 14:30:59 -0700 (PDT)\r
+Received: by ykaz22 with SMTP id z22so167484966yka.2\r
+ for <notmuch@notmuchmail.org>; Sun, 25 Oct 2015 14:30:59 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=sender:from:to:cc:subject:date:message-id;\r
+ bh=hwExSPfcPbcVtLo1/8+dcasX2JZ6MebErO0Ck/IymMo=;\r
+ b=y2jqdOyZgIZ2vBEpY5Juotsf3b6h9gNlDGCSodiwY7KHgf8Seeo+nJy8+JXEFeLawu\r
+ l5Oen3TnNtjL52HNIqHCgCEb273MveK0TAuMJFfcvWTaTGcLh/kslII70jD9PzAUJDJU\r
+ 10fFy4TWSJY3KEXCPAor1+NvFbcDMUlC+pzAgJC7vSokhccIcyUoGP/ZHZcFPnLFSCew\r
+ RZ6/2Pu4p9a7EH12SLU8KXapJiU3zkvHQyU589e4yM9foGEFxnPolIlLMt30sXmv/3n9\r
+ dT3SgA02O5Pfx2FCTlS5pn0j6gI0RfcSdHg9UZzzurGMToxze+pbgd/Ty1bdTvQhLQWx\r
+ bugA==\r
+X-Received: by 10.13.222.132 with SMTP id h126mr23309557ywe.128.1445808659093;\r
+ Sun, 25 Oct 2015 14:30:59 -0700 (PDT)\r
+Received: from localhost (pool-71-174-176-247.bstnma.east.verizon.net.\r
+ [71.174.176.247])\r
+ by smtp.gmail.com with ESMTPSA id s189sm15144720ywe.35.2015.10.25.14.30.58\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sun, 25 Oct 2015 14:30:58 -0700 (PDT)\r
+Sender: Steven <stebalien@gmail.com>\r
+From: Steven Allen <steven@stebalien.com>\r
+To: notmuch@notmuchmail.org\r
+Cc: Steven Allen <steven@stebalien.com>\r
+Subject: [PATCH] forbid atomic transactions on writable, upgradable databases\r
+Date: Sun, 25 Oct 2015 17:30:39 -0400\r
+Message-Id: <1445808639-5378-1-git-send-email-steven@stebalien.com>\r
+X-Mailer: git-send-email 2.6.2\r
+X-Mailman-Approved-At: Sun, 25 Oct 2015 14:34:16 -0700\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 25 Oct 2015 21:31:02 -0000\r
+\r
+We can't (but currently do) allow upgrades within transactions because\r
+upgrades need their own transactions. We don't want to re-use the\r
+current transaction because bailing out of an upgrade would mean loosing\r
+all previous changes (because our "atomic" transactions don't commit\r
+before hand). This gives us two options:\r
+\r
+1. Fail at the beginning of upgrade (tell the user to end the\r
+ transaction, upgrade, and start over).\r
+2. Don't allow the user to start the transaction.\r
+\r
+I went with the latter because:\r
+\r
+1. There is no reason to call `begin_atomic` unless you intend to to\r
+ write to the database and anyone intending to write to the database\r
+ should upgrade it first.\r
+2. This means that nothing inside an atomic transaction can ever fail\r
+ with NOTMUCH_STATUS_UPGRADE_REQUIRED.\r
+---\r
+ lib/database.cc | 3 +++\r
+ 1 file changed, 3 insertions(+)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 5e86955..3b342f1 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1635,6 +1635,9 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)\r
+ notmuch->atomic_nesting > 0)\r
+ goto DONE;\r
+ \r
++ if (notmuch_database_needs_upgrade(notmuch))\r
++ return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
++\r
+ try {\r
+ (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);\r
+ } catch (const Xapian::Error &error) {\r
+-- \r
+2.6.2\r
+\r