]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Perform the same transformation to _notmuch_database_find_directory_id
authorAustin Clements <amdragon@MIT.EDU>
Fri, 18 May 2012 04:13:35 +0000 (00:13 -0400)
committerDavid Bremner <bremner@debian.org>
Thu, 24 May 2012 01:30:32 +0000 (22:30 -0300)
Now _notmuch_database_find_directory_id takes a flags argument, which
it passes through to _notmuch_directory_create and can indicate if the
directory does not exist.  Again, callers have been updated, but
retain their original behavior.

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

index df996a9a0cf54ecd076245936dbd0c753a5d0906..716982d0e4cd279e9b734941c78e56aca84fbf37 100644 (file)
@@ -1197,9 +1197,17 @@ _notmuch_database_split_path (void *ctx,
     return NOTMUCH_STATUS_SUCCESS;
 }
 
+/* Find the document ID of the specified directory.
+ *
+ * If (flags & NOTMUCH_FIND_CREATE), a new directory document will be
+ * created if one does not exist for 'path'.  Otherwise, if the
+ * directory document does not exist, this sets *directory_id to
+ * ((unsigned int)-1) and returns NOTMUCH_STATUS_SUCCESS.
+ */
 notmuch_status_t
 _notmuch_database_find_directory_id (notmuch_database_t *notmuch,
                                     const char *path,
+                                    notmuch_find_flags_t flags,
                                     unsigned int *directory_id)
 {
     notmuch_directory_t *directory;
@@ -1210,8 +1218,8 @@ _notmuch_database_find_directory_id (notmuch_database_t *notmuch,
        return NOTMUCH_STATUS_SUCCESS;
     }
 
-    directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status);
-    if (status) {
+    directory = _notmuch_directory_create (notmuch, path, flags, &status);
+    if (status || !directory) {
        *directory_id = -1;
        return status;
     }
@@ -1260,7 +1268,7 @@ _notmuch_database_filename_to_direntry (void *ctx,
     if (status)
        return status;
 
-    status = _notmuch_database_find_directory_id (notmuch, directory,
+    status = _notmuch_database_find_directory_id (notmuch, directory, NOTMUCH_FIND_CREATE,
                                                  &directory_id);
     if (status)
        return status;
index 83bb19bce0378eae9d2ec5a0ad806eebb6076ec3..6a3ffed73bb6031d36cf579a700d4b67b6ba5ec6 100644 (file)
@@ -153,7 +153,13 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
 
            _notmuch_database_split_path (local, path, &parent, &basename);
 
-           _notmuch_database_find_directory_id (notmuch, parent, &parent_id);
+           *status_ret = _notmuch_database_find_directory_id (
+               notmuch, parent, NOTMUCH_FIND_CREATE, &parent_id);
+           if (*status_ret) {
+               notmuch_directory_destroy (directory);
+               directory = NULL;
+               goto DONE;
+           }
 
            if (basename) {
                term = talloc_asprintf (local, "%s%u:%s",
index 538274f416cbb32b2c5e778c3dea4a2fc0cbc359..a36549d292a55025645cf97356740b9e2f69572c 100644 (file)
@@ -195,6 +195,7 @@ _notmuch_database_find_unique_doc_id (notmuch_database_t *notmuch,
 notmuch_status_t
 _notmuch_database_find_directory_id (notmuch_database_t *database,
                                     const char *path,
+                                    notmuch_find_flags_t flags,
                                     unsigned int *directory_id);
 
 const char *