]> git.notmuchmail.org Git - notmuch/blobdiff - lib/directory.cc
lib: update commentary about path/folder terms
[notmuch] / lib / directory.cc
index 6a3ffed73bb6031d36cf579a700d4b67b6ba5ec6..4fcb017712f6c9c505a35326dc807f84b3e09d6d 100644 (file)
@@ -13,7 +13,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ * along with this program.  If not, see https://www.gnu.org/licenses/ .
  *
  * Author: Carl Worth <cworth@cworth.org>
  */
@@ -103,7 +103,12 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
     notmuch_directory_t *directory;
     notmuch_private_status_t private_status;
     const char *db_path;
-    notmuch_bool_t create = (flags & NOTMUCH_FIND_CREATE);
+    bool create = (flags & NOTMUCH_FIND_CREATE);
+
+    if (! (notmuch->features & NOTMUCH_FEATURE_DIRECTORY_DOCS)) {
+       *status_ret = NOTMUCH_STATUS_UPGRADE_REQUIRED;
+       return NULL;
+    }
 
     *status_ret = NOTMUCH_STATUS_SUCCESS;
 
@@ -181,10 +186,10 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
        directory->mtime = Xapian::sortable_unserialise (
            directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));
     } catch (const Xapian::Error &error) {
-       fprintf (stderr,
+       _notmuch_database_log (notmuch,
                 "A Xapian exception occurred creating a directory: %s.\n",
                 error.get_msg().c_str());
-       notmuch->exception_reported = TRUE;
+       notmuch->exception_reported = true;
        notmuch_directory_destroy (directory);
        directory = NULL;
        *status_ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
@@ -222,11 +227,14 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,
                                   Xapian::sortable_serialise (mtime));
 
        db->replace_document (directory->document_id, directory->doc);
+
+       directory->mtime = mtime;
+
     } catch (const Xapian::Error &error) {
-       fprintf (stderr,
+       _notmuch_database_log (notmuch,
                 "A Xapian exception occurred setting directory mtime: %s.\n",
                 error.get_msg().c_str());
-       notmuch->exception_reported = TRUE;
+       notmuch->exception_reported = true;
        return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
     }
 
@@ -276,6 +284,31 @@ notmuch_directory_get_child_directories (notmuch_directory_t *directory)
     return child_directories;
 }
 
+notmuch_status_t
+notmuch_directory_delete (notmuch_directory_t *directory)
+{
+    notmuch_status_t status;
+    Xapian::WritableDatabase *db;
+
+    status = _notmuch_database_ensure_writable (directory->notmuch);
+    if (status)
+       return status;
+
+    try {
+       db = static_cast <Xapian::WritableDatabase *> (directory->notmuch->xapian_db);
+       db->delete_document (directory->document_id);
+    } catch (const Xapian::Error &error) {
+       _notmuch_database_log (directory->notmuch,
+                              "A Xapian exception occurred deleting directory entry: %s.\n",
+                              error.get_msg().c_str());
+       directory->notmuch->exception_reported = true;
+       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+    }
+    notmuch_directory_destroy (directory);
+
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
 void
 notmuch_directory_destroy (notmuch_directory_t *directory)
 {