From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
To: notmuch@notmuchmail.org
Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
Subject: [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead of fclose
Date: Wed, 15 Feb 2012 17:02:05 -0500 [thread overview]
Message-ID: <1329343326-16410-13-git-send-email-glasse@cs.rpi.edu> (raw)
In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
From: Ethan Glasser-Camp <ethan@betacantrips.com>
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 <ethan@betacantrips.com>
---
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
next prev parent reply other threads:[~2012-02-15 22:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 22:01 [RFC PATCH 00/13] Modular message store code Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 01/13] Create configuration paramater database.type Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 02/13] Add the concept of a mailstore in its absolute minimal sense Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 03/13] Introduce mailstore in the python bindings Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 04/13] Replace remaining places where fopen occurs Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 05/13] notmuch_database_add_message calculates sha1 of messages using mailstore Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 06/13] Pass mailstore to _notmuch_message_index_file Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 07/13] notmuch-new: pull out useful bits of add_files_recursive Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 08/13] count_files and add_files shall be generic Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 09/13] Mailstore also provides a "rename" function Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 10/13] Introduce concept of mailstore "constructor" Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 11/13] Add a close function to mailstore Ethan Glasser-Camp
2012-02-15 22:02 ` Ethan Glasser-Camp [this message]
2012-02-15 22:02 ` [RFC PATCH 13/13] First crack at a CouchDB mailstore Ethan Glasser-Camp
2012-02-16 0:56 ` [RFC PATCH 00/13] Modular message store code Mark Walters
2012-03-01 13:51 ` Ethan Glasser-Camp
2012-02-16 7:47 ` Stewart Smith
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=1329343326-16410-13-git-send-email-glasse@cs.rpi.edu \
--to=glasse@cs.rpi.edu \
--cc=ethan@betacantrips.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).