From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id AAC876DE12C2 for ; Mon, 21 Aug 2017 08:45:04 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.212 X-Spam-Level: X-Spam-Status: No, score=-0.212 tagged_above=-999 required=5 tests=[AWL=0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.211, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z-eSyYxzm6KX for ; Mon, 21 Aug 2017 08:45:04 -0700 (PDT) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by arlo.cworth.org (Postfix) with ESMTPS id 81AF36DE1152 for ; Mon, 21 Aug 2017 08:45:02 -0700 (PDT) Received: by mail-wr0-f196.google.com with SMTP id k10so5653521wre.5 for ; Mon, 21 Aug 2017 08:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=83nd9GPQVfRQnWh5ZBoDIWoOW+I7bXPyVccOKvdBLKo=; b=Ne/nCQV8yz8TGwRFvbVW2G/57hSKWODxfwMJoBguBlKuLvQwkwH8Ah4Mh/qbVSNf5e p94Zv78Hm4J17fzyi+APpQZt44862ebIZWE1YS8+Bz/59bXus2T1t8LEo94/EzkzqJGx XGca/BOP+ztxyzo1MSHa4tPtL1yG6nKo2RF+L3FrBEiksxBSp88ivK5LgJ2HDNkWymUo ezpyGZjySYyqkQv91xuMH8hxj8HcrC17WDLuIrVszUAsfbJjVbXUDojLw2vhbQ2ZJDrj davOTVuD0uFU1K7eFA5swxjSJjNCzkUeNKNF5OZUZonZ91mAdAuo50fg7bVEabBdKBXa rfDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=83nd9GPQVfRQnWh5ZBoDIWoOW+I7bXPyVccOKvdBLKo=; b=Eiz3v1hs7/gtE6jSRjia15Yvh9FIsAf7smEsO/H3nomXjD7vEF1NZ63JXAj1N8iyzT f6s50e1QRp9FAjMH4LmzpvsqY402ZqIQuI0cL1QAPn0DK9KMwkn/QX1LY04ZZSlroECj 3sPCBWlKYJWLny2OUY0QNhCwLRPvFgHkkguDedyF73FkuzJs+y19UclFRSF/Li9GPCp6 3W2yHb92bQNeTfjl97Y+Qf/bklhBNlUomweV6YvlxTb6bRZmSLkN72vhWG6e7Ju3PpMe JL2BNtHbsN5/Emih768aZTALDLXIjDR0jIcEMWMd9YRH+I1BvCLE32rdHwHFzkitVDTR epbw== X-Gm-Message-State: AHYfb5jKQA91GOUsRZQnq17kiuvGA3Z5O1O1v2iuCgoYqOoXTKxQ/095 k/ndp7zhqBfVh5VKxTg= X-Received: by 10.223.164.197 with SMTP id h5mr2271131wrb.38.1503330300970; Mon, 21 Aug 2017 08:45:00 -0700 (PDT) Received: from localhost (mito.neclab.eu. [195.37.70.39]) by smtp.gmail.com with ESMTPSA id 26sm7474678wrx.26.2017.08.21.08.45.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Aug 2017 08:45:00 -0700 (PDT) From: Yuri Volchkov To: notmuch@notmuchmail.org Subject: [PATCH v2 4/4] show: workaround for the missing file problem Date: Mon, 21 Aug 2017 17:44:48 +0200 Message-Id: <1503330288-9375-5-git-send-email-yuri.volchkov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503330288-9375-1-git-send-email-yuri.volchkov@gmail.com> References: <1502556453-11609-1-git-send-email-yuri.volchkov@gmail.com> <1503330288-9375-1-git-send-email-yuri.volchkov@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Mon, 21 Aug 2017 15:45:04 -0000 This patch fixes the 'Deleted first duplicate file does not stop notmuch show from working' test. If a message to be shown has several duplicated files, and for some reason the first file in the list is not available anymore, notmuch will exit with an error. This is clearly a problem in the database, but we are not going to let this problem be a show-stopper. Let's walk through the list, and show the first existing file. Signed-off-by: Yuri Volchkov --- mime-node.c | 28 ++++++++++++++++++++++++---- test/T670-duplicate-mid.sh | 1 - 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/mime-node.c b/mime-node.c index bb0870d..24d73af 100644 --- a/mime-node.c +++ b/mime-node.c @@ -79,12 +79,32 @@ mime_node_open (const void *ctx, notmuch_message_t *message, } talloc_set_destructor (mctx, _mime_node_context_free); + /* Fast path */ mctx->file = fopen (filename, "r"); if (! mctx->file) { - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); - status = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } + /* Slow path - for some reason the first file in the list is + * not available anymore. This is clearly a problem in the + * database, but we are not going to let this problem be a + * show stopper */ + notmuch_filenames_t *filenames; + for (filenames = notmuch_message_get_filenames (message); + notmuch_filenames_valid (filenames); + notmuch_filenames_move_to_next (filenames)) + { + filename = notmuch_filenames_get (filenames); + mctx->file = fopen (filename, "r"); + if (mctx->file) + break; + } + + talloc_free (filenames); + if (! mctx->file) { + /* Give up */ + fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); + status = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + } mctx->stream = g_mime_stream_file_new (mctx->file); if (!mctx->stream) { diff --git a/test/T670-duplicate-mid.sh b/test/T670-duplicate-mid.sh index f6f1602..decbc0a 100755 --- a/test/T670-duplicate-mid.sh +++ b/test/T670-duplicate-mid.sh @@ -39,7 +39,6 @@ test_expect_equal_file EXPECTED OUTPUT rm ${MAIL_DIR}/copy1 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working' -test_subtest_known_broken output=$(notmuch show --body=false --format=json id:duplicate) expected='[[[{ "id": "'duplicate'", -- 2.7.4