unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Yuri Volchkov <yuri.volchkov@gmail.com>
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	[thread overview]
Message-ID: <1503330288-9375-5-git-send-email-yuri.volchkov@gmail.com> (raw)
In-Reply-To: <1503330288-9375-1-git-send-email-yuri.volchkov@gmail.com>

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 <yuri.volchkov@gmail.com>
---
 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

  parent reply	other threads:[~2017-08-21 15:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-12 16:47 [PATCH 0/4] fix "no such file" problem for emails send by emacs Yuri Volchkov
2017-08-12 16:47 ` [PATCH 1/4] test: insert into the folder with trailing / Yuri Volchkov
2017-08-17  1:21   ` David Bremner
2017-08-20 12:16   ` David Bremner
2017-08-12 16:47 ` [PATCH 2/4] insert: strip trailing / in folder path Yuri Volchkov
2017-08-19  0:17   ` David Bremner
2017-08-19  8:27     ` Yuri Volchkov
2017-08-19 12:55       ` David Bremner
2017-08-12 16:47 ` [PATCH 3/4] test: show id:<> works even if the first duplicated is deleted Yuri Volchkov
2017-08-12 16:47 ` [PATCH 4/4] show: workaround for the missing file problem Yuri Volchkov
2017-08-13 12:41 ` [PATCH 0/4] fix "no such file" problem for emails send by emacs David Bremner
2017-08-13 21:56   ` Yuri Volchkov
2017-08-16 11:32     ` David Bremner
2017-08-21 15:44 ` [PATCH v2 0/4] fix insufficient path canonization Yuri Volchkov
2017-08-21 15:44   ` [PATCH v2 1/4] database: move striping of trailing '/' into helper function Yuri Volchkov
2017-08-21 15:44   ` [PATCH v2 2/4] insert: strip trailing / in folder path Yuri Volchkov
2017-08-21 15:44   ` [PATCH v2 3/4] test: show id:<> works even if the first duplicate is deleted Yuri Volchkov
2017-08-21 15:44   ` Yuri Volchkov [this message]
2017-08-23  0:19   ` [PATCH v2 0/4] fix insufficient path canonization David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1503330288-9375-5-git-send-email-yuri.volchkov@gmail.com \
    --to=yuri.volchkov@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).