[RFC PATCH 11/13] Add a close function to mailstore
Ethan Glasser-Camp
glasse at cs.rpi.edu
Wed Feb 15 14:02:04 PST 2012
From: Ethan Glasser-Camp <ethan at betacantrips.com>
This is a useful way to signal to mailstores that the resources
associated with an existing FILE* are no longer being used and they
can be cleaned up. For maildir, of course, this is just a call to
fclose(), but for other mailstores this might involve freeing memory
or unlinking temporary files...
Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
lib/mailstore.c | 17 ++++++++++++++++-
lib/notmuch.h | 5 +++++
2 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/lib/mailstore.c b/lib/mailstore.c
index b4d512d..51c2710 100644
--- a/lib/mailstore.c
+++ b/lib/mailstore.c
@@ -24,6 +24,7 @@
typedef struct _notmuch_mailstore {
notmuch_status_t (*constructor) (void **data, va_list args);
FILE *(*open) (struct _notmuch_mailstore *mailstore, const char *filename);
+ int (*close) (struct _notmuch_mailstore *mailstore, FILE *);
int (*rename) (struct _notmuch_mailstore *mailstore, const char *old_filename,
const char *new_filename);
void *data;
@@ -44,6 +45,13 @@ _maildir_open_function (unused (notmuch_mailstore_t *mailstore),
}
static int
+_maildir_close_function (unused (notmuch_mailstore_t *mailstore),
+ FILE *file)
+{
+ return fclose (file);
+}
+
+static int
_maildir_rename_function (unused (notmuch_mailstore_t *mailstore),
const char *old_filename, const char *new_filename)
{
@@ -68,7 +76,8 @@ _maildir_rename_function (unused (notmuch_mailstore_t *mailstore),
*/
_notmuch_mailstore
notmuch_mailstore_maildir = { _maildir_constructor,
- _maildir_open_function, _maildir_rename_function,
+ _maildir_open_function, _maildir_close_function,
+ _maildir_rename_function,
NULL };
_notmuch_mailstore *
@@ -93,6 +102,12 @@ notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filena
return mailstore->rename (mailstore, old_filename, new_filename);
}
+int
+notmuch_mailstore_close (notmuch_mailstore_t *mailstore, FILE *file)
+{
+ return mailstore->close (mailstore, file);
+}
+
notmuch_status_t
notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 7f48507..d760d4f 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -423,6 +423,11 @@ notmuch_mailstore_get_by_name (const char *name);
FILE *
notmuch_mailstore_open (notmuch_mailstore_t *mailstore, const char *filename);
+/* Signal that a filename is no longer being used; get rid of its resources.
+ */
+int
+notmuch_mailstore_close (notmuch_mailstore_t *mailstore, FILE *file);
+
/* Rename a file. This is used to update maildir tags and can safely
* be a NO-OP for non-filesystem mailstores.
*/
--
1.7.5.4
More information about the notmuch
mailing list