]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Make notmuch_database_get_directory return NULL if the directory is not found
authorAustin Clements <amdragon@MIT.EDU>
Fri, 18 May 2012 04:13:37 +0000 (00:13 -0400)
committerDavid Bremner <bremner@debian.org>
Thu, 24 May 2012 01:30:55 +0000 (22:30 -0300)
Using the new support from _notmuch_directory_create, this makes
notmuch_database_get_directory a read-only operation that simply
returns the directory object if it exists or NULL otherwise.  This
also means that notmuch_database_get_directory can work on read-only
databases.

This change breaks the directory mtime workaround in notmuch-new.c by
fixing the exact issue it was working around.  This permits mtime
update races to prevent scans of changed directories, which
non-deterministically breaks a few tests.  The next patch fixes this.

lib/database.cc
lib/notmuch-private.h
lib/notmuch.h

index b4c76b4ea622e561729deb78a7874689dd766e15..e27a0e1664cfac7d2731402f7e3c675c19f57eda 100644 (file)
@@ -1328,12 +1328,9 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,
        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 {
-       *directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status);
+       *directory = _notmuch_directory_create (notmuch, path,
+                                               NOTMUCH_FIND_LOOKUP, &status);
     } catch (const Xapian::Error &error) {
        fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
                 error.get_msg().c_str());
index 34f7ac7c588f74eb80482bd91f7ff773cb1b90b6..bfb41116adcff104edadf639cd95513b225289bb 100644 (file)
@@ -148,6 +148,9 @@ typedef enum _notmuch_private_status {
 
 /* Flags shared by various lookup functions. */
 typedef enum _notmuch_find_flags {
+    /* Lookup without creating any documents.  This is the default
+     * behavior. */
+    NOTMUCH_FIND_LOOKUP = 0,
     /* If set, create the necessary document (or documents) if they
      * are missing.  Requires a read/write database. */
     NOTMUCH_FIND_CREATE = 1<<0,
index bbb17e4a66d5c3f5e6c7a9ba4c6990be0605883b..3633bedde20acafc064b62a52f319dcdde153111 100644 (file)
@@ -300,10 +300,8 @@ 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'.
  *
- * 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.
+ * If this directory object does not exist in the database, this
+ * returns NOTMUCH_STATUS_SUCCESS and sets *directory to NULL.
  *
  * Return value:
  *
@@ -313,10 +311,6 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);
  *
  * 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_status_t
 notmuch_database_get_directory (notmuch_database_t *database,