lib: eliminate fprintf from _notmuch_message_file_open
authorDavid Bremner <david@tethera.net>
Fri, 26 Dec 2014 17:34:49 +0000 (18:34 +0100)
committerDavid Bremner <david@tethera.net>
Sat, 28 Mar 2015 23:34:15 +0000 (00:34 +0100)
You may wonder why _notmuch_message_file_open_ctx has two parameters.
This is because we need sometime to use a ctx which is a
notmuch_message_t. While we could get the database from this, there is
no easy way in C to tell type we are getting.

lib/database.cc
lib/message-file.c
lib/message.cc
lib/notmuch-private.h

index 416d99c2bb12eabbb10195b8f84366b2210eb821..cffab62c895b3dd318855ae27445ad55488de97b 100644 (file)
@@ -2314,7 +2314,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
     if (ret)
        return ret;
 
-    message_file = _notmuch_message_file_open (filename);
+    message_file = _notmuch_message_file_open (notmuch, filename);
     if (message_file == NULL)
        return NOTMUCH_STATUS_FILE_ERROR;
 
index a41d9ad2a719df507d3091316d594bc38b3e4fc5..8ac96e8e06a5dd9a132f241469690c773777fdb4 100644 (file)
@@ -76,7 +76,8 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)
 /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as
  * the talloc owner. */
 notmuch_message_file_t *
-_notmuch_message_file_open_ctx (void *ctx, const char *filename)
+_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
+                               void *ctx, const char *filename)
 {
     notmuch_message_file_t *message;
 
@@ -98,16 +99,18 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
     return message;
 
   FAIL:
-    fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
+    _notmuch_database_log (notmuch, "Error opening %s: %s\n",
+                         filename, strerror (errno));
     _notmuch_message_file_close (message);
 
     return NULL;
 }
 
 notmuch_message_file_t *
-_notmuch_message_file_open (const char *filename)
+_notmuch_message_file_open (notmuch_database_t *notmuch,
+                           const char *filename)
 {
-    return _notmuch_message_file_open_ctx (NULL, filename);
+    return _notmuch_message_file_open_ctx (notmuch, NULL, filename);
 }
 
 void
index a8ca9884c911906735d6f25884500a1169f13e8c..5bc7aff1386a4a7e09a461f98f7e37f86e5a3f58 100644 (file)
@@ -437,7 +437,8 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
     if (unlikely (filename == NULL))
        return;
 
-    message->message_file = _notmuch_message_file_open_ctx (message, filename);
+    message->message_file = _notmuch_message_file_open_ctx (
+       _notmuch_message_database (message), message, filename);
 }
 
 const char *
index dc58a2fd9cfaa94b3fecce214ee77a17f92af260..cc9ce12ce69d664f708e96d93767355ecc1b4ff2 100644 (file)
@@ -358,11 +358,12 @@ typedef struct _notmuch_message_file notmuch_message_file_t;
  * Returns NULL if any error occurs.
  */
 notmuch_message_file_t *
-_notmuch_message_file_open (const char *filename);
+_notmuch_message_file_open (notmuch_database_t *notmuch, const char *filename);
 
 /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */
 notmuch_message_file_t *
-_notmuch_message_file_open_ctx (void *ctx, const char *filename);
+_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
+                               void *ctx, const char *filename);
 
 /* Close a notmuch message previously opened with notmuch_message_open. */
 void