From be3e2e476d1a4555f56926f02d675940d2596fe9 Mon Sep 17 00:00:00 2001 From: Ethan Glasser-Camp Date: Thu, 16 Feb 2012 17:02:05 +1900 Subject: [PATCH] [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead of fclose --- 53/45012626801f22531136105c565c733e5bb332 | 245 ++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 53/45012626801f22531136105c565c733e5bb332 diff --git a/53/45012626801f22531136105c565c733e5bb332 b/53/45012626801f22531136105c565c733e5bb332 new file mode 100644 index 000000000..8e3b41ea5 --- /dev/null +++ b/53/45012626801f22531136105c565c733e5bb332 @@ -0,0 +1,245 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id BA90B429E4D + for ; Wed, 15 Feb 2012 14:13:16 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.54 +X-Spam-Level: +X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3, + RCVD_IN_SORBS_WEB=0.614] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 7QlhXPbf2Al2 for ; + Wed, 15 Feb 2012 14:13:13 -0800 (PST) +Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu + [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS + id 01E6D429E48 for ; Wed, 15 Feb 2012 14:13:12 -0800 + (PST) +X-Hash: + S|a2909afab59f13fda5255d225e711418d0302a88|16748bbaf3acbf9f453a2d52848ce009 +X-Countries: Cameroon, United States +X-SMTP-From: accepted [195.24.209.20] [195.24.209.20] + (localhost) {Cameroon} +DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from + :to:cc:subject:date:message-id:in-reply-to:references; s= + default; i=glasse@cs.rpi.edu; t=1329343991; x=1329948791; l=4398; + bh=5+o6UHFRfrHjxJ956HhG8NvJO+A=; b=sDhJAIuW1pOJg/8HeFT6RTo + TnXPJ1uHI2FTUhINON/hfIxlDcK9h4vzJ50owdFnT8p3z8VQwsmOl4PfJgYYeAqg + NMkSs+J7aamb6dfO5zcQnm4tDysfFYtHL0acttDy/oVtqAO/+VNfMk053iHcRms+ + PiS54SvuwMiaCDH0mkt4= +DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc + :subject:date:message-id:in-reply-to:references; q=dns; s= + default; b=K5NQY77/tVz51x/iW5/NG/0HAjejEgiy4hGZNK8S4R2hgehhcyle4 + +gqp3cvqOPK5rdPMlEdbC1ZjqsnGmulh7HL/of2oy+STcTecAfXDQjjGXXeQ8XGG + hAYt/CR2Yj/dQtriNLKJG9kDc+RfraLQq9PvoWz25++YcXVInK6S3o= +X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00 +X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit + 15) +Authentication-Results: cliffclavin.cs.rpi.edu; + DKIM=neutral (none) header.from=glasse@cs.rpi.edu; + SPF=neutral (mfrom; + Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu +X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMCjUm008878 Auth:glasse +X-Virus-Scanned-By: cliffclavin.cs.rpi.edu +Received: from localhost ([195.24.209.20]) (authenticated bits=0) + by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMCjUm008878 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); + Wed, 15 Feb 2012 17:12:56 -0500 (EST) + (envelope-from glasse@cs.rpi.edu) +From: Ethan Glasser-Camp +To: notmuch@notmuchmail.org +Subject: [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead + of fclose +Date: Wed, 15 Feb 2012 17:02:05 -0500 +Message-Id: <1329343326-16410-13-git-send-email-glasse@cs.rpi.edu> +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> +References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> +X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25 +Cc: Ethan Glasser-Camp +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Wed, 15 Feb 2012 22:13:16 -0000 + +From: Ethan Glasser-Camp + +This requires a little bit of juggling in lib/sha1.c. Wrapper +functions provide the FILE*. Instead of closing the file immediately +ourselves, we let the wrapper functions close it. + +Signed-off-by: Ethan Glasser-Camp +--- + lib/message-file.c | 6 ++++-- + lib/sha1.c | 14 ++++++++------ + mime-node.c | 4 +++- + notmuch-show.c | 8 ++++---- + 4 files changed, 19 insertions(+), 13 deletions(-) + +diff --git a/lib/message-file.c b/lib/message-file.c +index 61f4d04..51c77f9 100644 +--- a/lib/message-file.c ++++ b/lib/message-file.c +@@ -34,6 +34,7 @@ typedef struct { + + struct _notmuch_message_file { + /* File object */ ++ notmuch_mailstore_t *mailstore; + FILE *file; + + /* Header storage */ +@@ -86,7 +87,7 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message) + g_hash_table_destroy (message->headers); + + if (message->file) +- fclose (message->file); ++ notmuch_mailstore_close (message->mailstore, message->file); + + return 0; + } +@@ -105,6 +106,7 @@ _notmuch_message_file_open_ctx (void *ctx, notmuch_mailstore_t *mailstore, + + talloc_set_destructor (message, _notmuch_message_file_destructor); + ++ message->mailstore = mailstore; + message->file = notmuch_mailstore_open (mailstore, filename); + if (message->file == NULL) + goto FAIL; +@@ -363,7 +365,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message, + } + + if (message->parsing_finished) { +- fclose (message->file); ++ notmuch_mailstore_close (message->mailstore, message->file); + message->file = NULL; + } + +diff --git a/lib/sha1.c b/lib/sha1.c +index ea25999..4266720 100644 +--- a/lib/sha1.c ++++ b/lib/sha1.c +@@ -87,7 +87,6 @@ _notmuch_sha1_of_filep (FILE *file) + if (feof (file)) { + break; + } else if (ferror (file)) { +- fclose (file); + return NULL; + } + } else { +@@ -99,8 +98,6 @@ _notmuch_sha1_of_filep (FILE *file) + + result = _hex_of_sha1_digest (digest); + +- fclose (file); +- + return result; + } + +@@ -117,9 +114,12 @@ char * + notmuch_sha1_of_file (const char *filename) + { + FILE *file; ++ char *ret; + + file = fopen (filename, "r"); +- return _notmuch_sha1_of_filep (file); ++ ret = _notmuch_sha1_of_filep (file); ++ fclose (file); ++ return ret; + } + + /* Create a hexadecimal string version of the SHA-1 digest of the +@@ -135,7 +135,9 @@ char * + notmuch_sha1_of_message (notmuch_mailstore_t *mailstore, const char *filename) + { + FILE *file; +- ++ char *ret; + file = notmuch_mailstore_open (mailstore, filename); +- return _notmuch_sha1_of_filep (file); ++ ret = _notmuch_sha1_of_filep (file); ++ notmuch_mailstore_close (mailstore, file); ++ return ret; + } +diff --git a/mime-node.c b/mime-node.c +index 856fc3b..db37189 100644 +--- a/mime-node.c ++++ b/mime-node.c +@@ -27,6 +27,7 @@ + typedef struct mime_node_context { + /* Per-message resources. These are allocated internally and must + * be destroyed. */ ++ notmuch_mailstore_t *mailstore; + FILE *file; + GMimeStream *stream; + GMimeParser *parser; +@@ -54,7 +55,7 @@ _mime_node_context_free (mime_node_context_t *res) + g_object_unref (res->stream); + + if (res->file) +- fclose (res->file); ++ notmuch_mailstore_close (res->mailstore, res->file); + + return 0; + } +@@ -90,6 +91,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message, + } + talloc_set_destructor (mctx, _mime_node_context_free); + ++ mctx->mailstore = mailstore; + mctx->file = notmuch_mailstore_open (mailstore, filename); + if (! mctx->file) { + fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); +diff --git a/notmuch-show.c b/notmuch-show.c +index 0d2a246..2e8e4c9 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -309,7 +309,7 @@ format_message_mbox (const void *ctx, + + printf ("\n"); + +- fclose (file); ++ notmuch_mailstore_close (mailstore, file); + } + + static void +@@ -966,18 +966,18 @@ do_show_single (void *ctx, + size = fread (buf, 1, sizeof (buf), file); + if (ferror (file)) { + fprintf (stderr, "Error: Read failed from %s\n", filename); +- fclose (file); ++ notmuch_mailstore_close (mailstore, file); + return 1; + } + + if (fwrite (buf, size, 1, stdout) != 1) { + fprintf (stderr, "Error: Write failed\n"); +- fclose (file); ++ notmuch_mailstore_close (mailstore, file); + return 1; + } + } + +- fclose (file); ++ notmuch_mailstore_close (mailstore, file); + + } else { + +-- +1.7.5.4 + -- 2.26.2