-notmuch_status_t
-notmuch_database_set_directory_mtime (notmuch_database_t *notmuch,
- const char *path,
- time_t mtime)
-{
- Xapian::Document doc;
- Xapian::WritableDatabase *db;
- unsigned int doc_id;
- notmuch_private_status_t status;
- notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
- const char *parent, *db_path = NULL;
- unsigned int parent_id;
- void *local = talloc_new (notmuch);
-
- if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
- fprintf (stderr, "Attempted to update a read-only database.\n");
- return NOTMUCH_STATUS_READONLY_DATABASE;
- }
-
- path = _notmuch_database_relative_path (notmuch, path);
-
- db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
- db_path = directory_db_path (path);
-
- try {
- status = find_directory_document (notmuch, db_path, &doc, &doc_id);
-
- doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
- Xapian::sortable_serialise (mtime));
-
- if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
- char *term = talloc_asprintf (local, "%s%s",
- _find_prefix ("directory"), db_path);
- doc.add_term (term);
-
- doc.set_data (path);
-
- _notmuch_database_split_path (local, path, &parent, NULL);
-
- _notmuch_database_find_directory_id (notmuch, parent, &parent_id);
-
- term = talloc_asprintf (local, "%s%u",
- _find_prefix ("parent"),
- parent_id);
- doc.add_term (term);
-
- db->add_document (doc);
- } else {
- db->replace_document (doc_id, doc);
- }
-
- } catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred setting directory mtime: %s.\n",
- error.get_msg().c_str());
- notmuch->exception_reported = TRUE;
- ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
- }
-
- if (db_path != path)
- free ((char *) db_path);
-
- talloc_free (local);
-
- return ret;
-}
-
-time_t
-notmuch_database_get_directory_mtime (notmuch_database_t *notmuch,
- const char *path)