--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 175CA431FC4\r
+ for <notmuch@notmuchmail.org>; Thu, 14 Nov 2013 06:38:00 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4mvrzmNt+C1u for <notmuch@notmuchmail.org>;\r
+ Thu, 14 Nov 2013 06:37:52 -0800 (PST)\r
+Received: from mail-we0-f171.google.com (mail-we0-f171.google.com\r
+ [74.125.82.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D331A431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 14 Nov 2013 06:37:51 -0800 (PST)\r
+Received: by mail-we0-f171.google.com with SMTP id t61so2069322wes.30\r
+ for <notmuch@notmuchmail.org>; Thu, 14 Nov 2013 06:37:50 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=F3IuyrOG7YiYZmu+/JjuBX7uIKx/i8LT5IMR2uTJDpk=;\r
+ b=LB1OhFHWV6qeAl6sV5BC6CkvA4VbRH9dvf7wnjL8Bv3wiXGZ8qln7hGzx331bo9NLd\r
+ bT/K0vGN08i/QQulLwshhrp/qZJ7fhe4/lvT3cTr2SASA9pfimaWIS8vvGFjuETpUL1M\r
+ JkDYYOQfZZeBxL0aGGFQS3PfVg0NFiF6bT0tVhS4YX4sZ5VTXMRQr7J27NagTplGF0Xt\r
+ zHGo/8W0w1+8CqCDSVuR41jXiZdbUDY6j9/4LjfhIJxXoocOilpFOBUo5SovoFQV0lF3\r
+ a6yseB3eLQVPxFlXsSWVb4UjZ/LMgDQ31sBsyrAecjvz2szndoqvkKzYcSuy6y1AG0x4\r
+ o5Ag==\r
+X-Gm-Message-State:\r
+ ALoCoQl6up+nUhzxy5v3oxhQUZuyhU5DjwhnPd2gcp/wKIDKsKEV+kYZFpU53jffbC7gHtXRaps6\r
+X-Received: by 10.180.89.98 with SMTP id bn2mr2824161wib.63.1384438151571;\r
+ Thu, 14 Nov 2013 06:09:11 -0800 (PST)\r
+Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
+ by mx.google.com with ESMTPSA id x19sm5550103wia.5.2013.11.14.06.09.10\r
+ for <multiple recipients>\r
+ (version=TLSv1.1 cipher=RC4-SHA bits=128/128);\r
+ Thu, 14 Nov 2013 06:09:10 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 3/5] compact: preserve backup database until compacted\r
+ database is in place\r
+In-Reply-To: <1384362167-12740-4-git-send-email-tomi.ollila@iki.fi>\r
+References: <1384362167-12740-1-git-send-email-tomi.ollila@iki.fi>\r
+ <1384362167-12740-4-git-send-email-tomi.ollila@iki.fi>\r
+User-Agent: Notmuch/0.16+115~gd647c65 (http://notmuchmail.org) Emacs/23.2.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Thu, 14 Nov 2013 15:08:55 +0100\r
+Message-ID: <874n7fnki0.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 14 Nov 2013 14:38:00 -0000\r
+\r
+On Wed, 13 Nov 2013, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> It is less error prone and window of failure opportunity is smaller\r
+> if the old (backup) database is always renamed (instead of sometimes\r
+> rmtree'd) before new (compacted) database is put into its place.\r
+> Finally rmtree() old database in case old database backup is not kept.\r
+> ---\r
+> lib/database.cc | 42 +++++++++++++++++++++++++-----------------\r
+> 1 file changed, 25 insertions(+), 17 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 3530cb6..ee09c5e 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -873,6 +873,7 @@ notmuch_database_compact (const char *path,\r
+> notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
+> notmuch_database_t *notmuch = NULL;\r
+> struct stat statbuf;\r
+> + notmuch_bool_t keep_backup;\r
+> \r
+> local = talloc_new (NULL);\r
+> if (! local)\r
+> @@ -898,17 +899,25 @@ notmuch_database_compact (const char *path,\r
+> goto DONE;\r
+> }\r
+> \r
+> - if (backup_path != NULL) {\r
+> - if (stat (backup_path, &statbuf) != -1) {\r
+> - fprintf (stderr, "Backup path already exists: %s\n", backup_path);\r
+> - ret = NOTMUCH_STATUS_FILE_ERROR;\r
+> - goto DONE;\r
+> - }\r
+> - if (errno != ENOENT) {\r
+> - fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",\r
+> - strerror (errno));\r
+> + if (backup_path == NULL) {\r
+> + if (! (backup_path = talloc_asprintf (local, "%s.old", xapian_path))) {\r
+> + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> goto DONE;\r
+> }\r
+> + keep_backup = FALSE;\r
+> + }\r
+> + else\r
+> + keep_backup = TRUE;\r
+\r
+*cough* I thought you were the style police around here *cough*\r
+\r
+> +\r
+> + if (stat (backup_path, &statbuf) != -1) {\r
+> + fprintf (stderr, "Backup path already exists: %s\n", backup_path);\r
+\r
+The user will be confused if he specifically didn't add --backup and\r
+happens to get this. But maybe it's a corner case. *shrug*.\r
+\r
+> + ret = NOTMUCH_STATUS_FILE_ERROR;\r
+> + goto DONE;\r
+> + }\r
+> + if (errno != ENOENT) {\r
+> + fprintf (stderr, "Unknown error while stat()ing backup path: %s\n",\r
+> + strerror (errno));\r
+\r
+ret = ?\r
+\r
+> + goto DONE;\r
+> }\r
+> \r
+> try {\r
+> @@ -924,14 +933,10 @@ notmuch_database_compact (const char *path,\r
+> goto DONE;\r
+> }\r
+> \r
+> - if (backup_path) {\r
+> - if (rename (xapian_path, backup_path)) {\r
+> - fprintf (stderr, "Error moving old database out of the way\n");\r
+> - ret = NOTMUCH_STATUS_FILE_ERROR;\r
+> - goto DONE;\r
+> - }\r
+> - } else {\r
+> - rmtree (xapian_path);\r
+> + if (rename (xapian_path, backup_path)) {\r
+> + fprintf (stderr, "Error moving old database out of the way\n");\r
+> + ret = NOTMUCH_STATUS_FILE_ERROR;\r
+> + goto DONE;\r
+> }\r
+> \r
+> if (rename (compact_xapian_path, xapian_path)) {\r
+> @@ -940,6 +945,9 @@ notmuch_database_compact (const char *path,\r
+> goto DONE;\r
+> }\r
+> \r
+> + if (! keep_backup)\r
+> + rmtree (backup_path);\r
+> +\r
+> DONE:\r
+> if (notmuch)\r
+> notmuch_database_destroy (notmuch);\r
+> -- \r
+> 1.8.3.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r