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 C510E6DE1161 for ; Sat, 12 Aug 2017 09:47:51 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.47 X-Spam-Level: X-Spam-Status: No, score=0.47 tagged_above=-999 required=5 tests=[AWL=-0.024, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=0.614, 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 5fpiooYAz4J1 for ; Sat, 12 Aug 2017 09:47:51 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id C2D266DE115C for ; Sat, 12 Aug 2017 09:47:50 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id d40so9733806wma.3 for ; Sat, 12 Aug 2017 09:47:50 -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=T+SV9zHPHNDxaivE8Gy81ocN4o5JQoVppLI15azdDIY=; b=MxmeC6hlD2GWNdxBT/5Q+kEO2mcCnXwMrwq6IjNyDTZf26FrZuIJfZhQnY5bbM85UQ Fg791AkfZOY8WuBsXGfd2fALAW3GMAjaAniFhAKsK7d8AtooF06MtA1S/jEnnK/+pu2a AQW3lvpXuW9Pzo96y8ggfcbfXsYZQqZIXC+TN1xRI1oWdT/wsFlTxaPGWHIWblLqxB4u xXGFEOmTTxiD6nJJghEvie1sd4r87Q7091M6N/FdaQLThY7WE6xw2JCQiRPdYrPdG+PH mRqaMvdgPwDYPiCfqig0E4s8EdMIYr1JrHJqXKfUQxg6/dTKrXu9YlvSvwPmzZc18lRM B5GA== 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=T+SV9zHPHNDxaivE8Gy81ocN4o5JQoVppLI15azdDIY=; b=UWcOzg91bPNY04Yq61kETj0jfgE226Z+x6TVbgafz+o+UpTyARGusZ3QicVIbxC2Q9 kut4Z2wh84xbUFSQHIeK/Scnvgzvv76mNI1DylFG1AAsrnCynKg/s9iIbTqGKtdeU+Qo vjjpj1dAfkJlK3AnMq6dGtGrGY0st4x02JxYq+THcoW4b+sBssdURekkg8vQH7Pyh09I G5oVIWBtZ0LdSR2unu1e2ptsAZ3OFSMYqOjjWVr31DLkfpqMDuZnPb1JgeLOcO114BPu KFljzT2tNj3D13+r/8jKJTCHIgpqfwZ5hvyNK5LOwrINanNfahsrvjXEHBu/GEnRpf5x BmAA== X-Gm-Message-State: AHYfb5iyORQxjY3t9TkEsYLdS3d7rcGiOoQfDrMzUpuzQUxonr2mXyy3 DKtcxYwhBN+N3MsCDz0= X-Received: by 10.28.18.66 with SMTP id 63mr1483794wms.20.1502556469069; Sat, 12 Aug 2017 09:47:49 -0700 (PDT) Received: from localhost (HSI-KBW-046-005-019-096.hsi8.kabel-badenwuerttemberg.de. [46.5.19.96]) by smtp.gmail.com with ESMTPSA id m127sm1828910wmm.46.2017.08.12.09.47.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Aug 2017 09:47:48 -0700 (PDT) From: Yuri Volchkov To: notmuch@notmuchmail.org Subject: [PATCH 4/4] show: workaround for the missing file problem Date: Sat, 12 Aug 2017 18:47:33 +0200 Message-Id: <1502556453-11609-5-git-send-email-yuri.volchkov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502556453-11609-1-git-send-email-yuri.volchkov@gmail.com> References: <1502556453-11609-1-git-send-email-yuri.volchkov@gmail.com> X-Mailman-Approved-At: Sat, 12 Aug 2017 13:16:46 -0700 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: Sat, 12 Aug 2017 16:47:51 -0000 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 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 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 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) { -- 2.7.4