aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/database.cc22
-rw-r--r--lib/notmuch.h23
2 files changed, 36 insertions, 9 deletions
diff --git a/lib/database.cc b/lib/database.cc
index 07f186ed..f8c4a7d1 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -955,8 +955,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
mtime = Xapian::sortable_unserialise (
document.get_value (NOTMUCH_VALUE_TIMESTAMP));
- directory = notmuch_database_get_directory (notmuch,
- term.c_str() + 10);
+ directory = _notmuch_directory_create (notmuch, term.c_str() + 10,
+ &status);
notmuch_directory_set_mtime (directory, mtime);
notmuch_directory_destroy (directory);
}
@@ -1304,20 +1304,30 @@ _notmuch_database_relative_path (notmuch_database_t *notmuch,
return relative;
}
-notmuch_directory_t *
+notmuch_status_t
notmuch_database_get_directory (notmuch_database_t *notmuch,
- const char *path)
+ const char *path,
+ notmuch_directory_t **directory)
{
notmuch_status_t status;
+ if (directory == NULL)
+ return NOTMUCH_STATUS_NULL_POINTER;
+ *directory = NULL;
+
+ /* XXX Handle read-only databases properly */
+ if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
+ return NOTMUCH_STATUS_READ_ONLY_DATABASE;
+
try {
- return _notmuch_directory_create (notmuch, path, &status);
+ *directory = _notmuch_directory_create (notmuch, path, &status);
} catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
- return NULL;
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
+ return status;
}
/* Allocate a document ID that satisfies the following criteria:
diff --git a/lib/notmuch.h b/lib/notmuch.h
index e6e5cc2e..bbb17e4a 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -300,11 +300,28 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);
* (see notmuch_database_get_path), or else should be an absolute path
* with initial components that match the path of 'database'.
*
- * Can return NULL if a Xapian exception occurs.
+ * Note: Currently this will create the directory object if it doesn't
+ * exist. In the future, when a directory object does not exist this
+ * will return NOTMUCH_STATUS_SUCCESS and set *directory to NULL.
+ * Callers should be prepared for this.
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Successfully retrieved directory.
+ *
+ * NOTMUCH_STATUS_NULL_POINTER: The given 'directory' argument is NULL.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
+ * directory not retrieved.
+ *
+ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
+ * mode so the directory cannot be created (this case will be
+ * removed in the future).
*/
-notmuch_directory_t *
+notmuch_status_t
notmuch_database_get_directory (notmuch_database_t *database,
- const char *path);
+ const char *path,
+ notmuch_directory_t **directory);
/* Add a new message to the given notmuch database or associate an
* additional filename with an existing message.