summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
8a810c4)
Previously, notmuch_database_get_directory had no way to indicate how
it had failed. This changes its prototype to return a status code and
set an out-argument to the retrieved directory, like similar functions
in the library API. This does *not* change its currently broken
behavior of creating directory objects when they don't exist, but it
does document it and paves the way for fixing this. Also, it can now
check for a read-only database and return
NOTMUCH_STATUS_READ_ONLY_DATABASE instead of crashing.
In the interest of atomicity, this also updates calls from the CLI so
that notmuch still compiles.
mtime = Xapian::sortable_unserialise (
document.get_value (NOTMUCH_VALUE_TIMESTAMP));
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);
}
notmuch_directory_set_mtime (directory, mtime);
notmuch_directory_destroy (directory);
}
notmuch_database_get_directory (notmuch_database_t *notmuch,
notmuch_database_get_directory (notmuch_database_t *notmuch,
+ const char *path,
+ notmuch_directory_t **directory)
{
notmuch_status_t status;
{
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;
+
- 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;
} catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
/* Allocate a document ID that satisfies the following criteria:
}
/* Allocate a document ID that satisfies the following criteria:
* (see notmuch_database_get_path), or else should be an absolute path
* with initial components that match the path of 'database'.
*
* (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_database_get_directory (notmuch_database_t *database,
notmuch_database_get_directory (notmuch_database_t *database,
+ 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.
/* Add a new message to the given notmuch database or associate an
* additional filename with an existing message.
notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
notmuch_message_t *message = NULL;
struct dirent **fs_entries = NULL;
notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
notmuch_message_t *message = NULL;
struct dirent **fs_entries = NULL;
+ int i, num_fs_entries = 0;
notmuch_directory_t *directory;
notmuch_filenames_t *db_files = NULL;
notmuch_filenames_t *db_subdirs = NULL;
notmuch_directory_t *directory;
notmuch_filenames_t *db_files = NULL;
notmuch_filenames_t *db_subdirs = NULL;
- directory = notmuch_database_get_directory (notmuch, path);
- db_mtime = notmuch_directory_get_mtime (directory);
+ status = notmuch_database_get_directory (notmuch, path, &directory);
+ if (status) {
+ ret = status;
+ goto DONE;
+ }
+ db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;
new_directory = db_mtime ? FALSE : TRUE;
new_directory = db_mtime ? FALSE : TRUE;
* by a new out-argument, or by recording this information and
* providing an accessor.
*/
* by a new out-argument, or by recording this information and
* providing an accessor.
*/
+ if (new_directory && directory)
notmuch_directory_set_mtime (directory, -1);
/* If the database knows about this directory, then we sort based
notmuch_directory_set_mtime (directory, -1);
/* If the database knows about this directory, then we sort based
notmuch_filenames_t *files, *subdirs;
char *absolute;
notmuch_filenames_t *files, *subdirs;
char *absolute;
- directory = notmuch_database_get_directory (notmuch, path);
+ status = notmuch_database_get_directory (notmuch, path, &directory);
+ if (status || !directory)
+ return status;
for (files = notmuch_directory_get_child_files (directory);
notmuch_filenames_valid (files);
for (files = notmuch_directory_get_child_files (directory);
notmuch_filenames_valid (files);
}
for (f = add_files_state.directory_mtimes->head; f && !interrupted; f = f->next) {
}
for (f = add_files_state.directory_mtimes->head; f && !interrupted; f = f->next) {
+ notmuch_status_t status;
notmuch_directory_t *directory;
notmuch_directory_t *directory;
- directory = notmuch_database_get_directory (notmuch, f->filename);
- if (directory) {
+ status = notmuch_database_get_directory (notmuch, f->filename, &directory);
+ if (status == NOTMUCH_STATUS_SUCCESS && directory) {
notmuch_directory_set_mtime (directory, f->mtime);
notmuch_directory_destroy (directory);
}
notmuch_directory_set_mtime (directory, f->mtime);
notmuch_directory_destroy (directory);
}