aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/database.cc
Commit message (Collapse)AuthorAge
* lib: Make notmuch_database_find_message_by_filename not crash on read-only ↵Gravatar Austin Clements2012-05-23
| | | | | | | | | | | databases Previously, _notmuch_database_filename_to_direntry would abort with an internal error when called on a read-only database. Now that creating the directory document is optional, notmuch_database_find_message_by_filename can disable directory document creation (as it should) and, as a result, not abort on read-only databases.
* lib: Make notmuch_database_get_directory return NULL if the directory is not ↵Gravatar Austin Clements2012-05-23
| | | | | | | | | | | | | | | found 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: Perform the same transformation to _notmuch_database_filename_to_direntryGravatar Austin Clements2012-05-23
| | | | | | Now _notmuch_database_filename_to_direntry takes a flags argument and can indicate if the necessary directory documents do not exist. Again, callers have been updated, but retain their original behavior.
* lib: Perform the same transformation to _notmuch_database_find_directory_idGravatar Austin Clements2012-05-23
| | | | | | | 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: Make directory document creation optional for _notmuch_directory_createGravatar Austin Clements2012-05-23
| | | | | | | | | | | Previously this function would create directory documents if they didn't exist. As a result, it could only be used on writable databases. This adds an argument to make creation optional and to make this function work on read-only databases. We use a flag argument to avoid a bare boolean and to permit future expansion. Both callers have been updated, but currently retain the old behavior. We'll take advantage of the new argument in the following patches.
* lib/cli: Make notmuch_database_get_directory return a status codeGravatar Austin Clements2012-05-15
| | | | | | | | | | | | | | 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.
* lib/cli: Make notmuch_database_create return a status codeGravatar Austin Clements2012-05-05
| | | | | | | | This is the notmuch_database_create equivalent of the previous change. In this case, there were places where errors were not being propagated correctly in notmuch_database_create or in calls to it. These have been fixed, using the new status value.
* lib/cli: Make notmuch_database_open return a status codeGravatar Austin Clements2012-05-05
| | | | | | | | | | | | It has been a long-standing issue that notmuch_database_open doesn't return any indication of why it failed. This patch changes its prototype to return a notmuch_status_t and set an out-argument to the database itself, like other functions that return both a status and an object. In the interest of atomicity, this also updates every use in the CLI so that notmuch still compiles. Since this patch does not update the bindings, the Python bindings test fails.
* Split notmuch_database_close into two functionsGravatar Justus Winter2012-04-28
| | | | | | | | | | | | | | | | | | Formerly notmuch_database_close closed the xapian database and destroyed the talloc structure associated with the notmuch database object. Split notmuch_database_close into notmuch_database_close and notmuch_database_destroy. This makes it possible for long running programs to close the xapian database and thus release the lock associated with it without destroying the data structures obtained from it. This also makes the api more consistent since every other data structure has a destructor function. The comments in notmuch.h are a courtesy of Austin Clements. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
* Fix error reporting in notmuch_database_find_message_by_filenameGravatar Justus Winter2012-03-18
| | | | | | | | | Formerly it was possible for *message_ret to be left uninitialized. The documentation however clearly states that "[o]n any failure or when the message is not found, this function initializes '*message' to NULL". Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
* Actually close the xapian database in notmuch_database_closeGravatar Justus Winter2012-03-03
| | | | | | | | | | | Formerly the xapian database object was deleted and closed in its destructor once the object was garbage collected. Explicitly call close() so that the database and the associated lock is released immediately. The comment is a courtesy of Austin Clements. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
* Prevent segmentation fault in notmuch_database_closeGravatar Justus Winter2012-02-20
| | | | | | | | | | | | Previously opening a notmuch database in read write mode that has been locked resulted in the notmuch_database_open function executing notmuch_database_close as a cleanup function. notmuch_database_close failed to check whether the xapian database has in fact been created. Add a check whether the xapian database object has actually been created before trying to call its flush method. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
* lib: Use talloc to simplify cleanup in notmuch_database_openGravatar Austin Clements2012-02-03
| | | | | | | Previously, we manually "free"d various pointers in notmuch_database_open. Use a local talloc context instead to simplify cleanup and eliminate various NULL pointer initializations and conditionals.
* lib: Release resources if notmuch_database_open failsGravatar Austin Clements2012-02-03
| | | | | Previously, if a Xapian exception occurred in notmuch_database_open, we failed to clean up the allocated notmuch_database_t object.
* lib: Don't delete uninitialized pointersGravatar Austin Clements2012-02-03
| | | | | | | | | In the error-handling paths of notmuch_database_open, we call notmuch_database_close, which "delete"s several objects referenced by the notmuch_database_t object. However, some of these pointers may be uninitialized, resulting in undefined behavior. Hence, allocate the notmuch_database_t with talloc_zero to make sure these pointers are NULL so that "delete"ing them is harmless.
* lib: call g_mime_init() from notmuch_database_open()Gravatar Kazuo Teramoto2011-12-31
| | | | | | | | | | | | | | As reported in id:"CAEbOPGyuHnz4BPtDutnTPUHcP3eYcRCRkXhYoJR43RUMw671+g@mail.gmail.com" sometimes gmime tries to access a NULL pointer, e.g. g_mime_iconv_open() tries to access iconv_cache that is NULL if g_mime_init() is not called. This causes notmuch to segfault when calling gmime functions. Calling g_mime_init() initializes iconv_cache and others variables needed by gmime, making sure they are initialized when notmuch calls gmime functions. Test marked fix by db.
* Fix comments about what is stored in the databaseGravatar Thomas Jost2011-12-23
| | | | | | Commit 567bcbc2 introduced two new values for each message (content of the "From" and "Subject" headers), but the comments about the database schema had not been updated accordingly.
* notmuch: Quiet buildbot warnings.Gravatar David Edmondson2011-12-21
| | | | | Cast away the result of various *write functions. Provide a default value for some variables to avoid "use before set" warnings.
* lib: call g_type_init from notmuch_database_openGravatar David Bremner2011-12-04
| | | | | We want to make sure g_type_init is called before any GObject functionality is used.
* Store "from" and "subject" headers in the database.Gravatar Austin Clements2011-11-14
| | | | | | | | | | | | | | This is a rebase and cleanup of Istvan Marko's patch from id:m3pqnj2j7a.fsf@zsu.kismala.com Search retrieves these headers for every message in the search results. Previously, this required opening and parsing every message file. Storing them directly in the database significantly reduces IO and computation, speeding up search by between 50% and 10X. Taking full advantage of this requires a database rebuild, but it will fall back to the old behavior for messages that do not have headers stored in the database.
* lib/database.cc: use flush Xapian method instead of commitGravatar David Bremner2011-11-02
| | | | | | | Apparently the method was renamed in Xapian 1.1.0 but the old method name will stay around for a while. It seems better to stick with the old name to make notmuch compile with older versions of Xapian, at least for now.
* xutil.c: remove duplicate copies, create new library libutil.a to contain xutil.Gravatar David Bremner2011-10-30
| | | | | | | We keep the lib/xutil.c version. As a consequence, also factor out _internal_error and associated macros. It might be overkill to make a new file error_util.c for this, but _internal_error does not really belong in database.cc.
* lib: make find_message{,by_filename) report errorsGravatar Ali Polatel2011-10-04
| | | | | | | | | | | | | | | | Previously, the functions notmuch_database_find_message() and notmuch_database_find_message_by_filename() functions did not properly report error condition to the library user. For more information, read the thread on the notmuch mailing list starting with my mail "id:871uv2unfd.fsf@gmail.com" Make these functions accept a pointer to 'notmuch_message_t' as argument and return notmuch_status_t which may be used to check for any error condition. restore: Modify for the new notmuch_database_find_message() new: Modify for the new notmuch_database_find_message_by_filename()
* lib: destroy message object after message removalGravatar Ali Polatel2011-10-04
| | | | | notmuch_database_remove_message() must call notmuch_message_destroy() once it is done handling message removal.
* lib: Wrap notmuch_database_add_message in an atomic section.Gravatar Austin Clements2011-09-24
| | | | | | | | Adding a message may involve changes to multiple database documents, and thus needs to be done in a transaction. This makes add_message (and, I think, the whole library) atomicity-safe: library callers only needs to use atomic sections if they needs atomicity across multiple library calls.
* lib: Add an API to find a message by filename.Gravatar Austin Clements2011-09-24
| | | | | | | | | notmuch_database_find_message_by_filename is mostly stolen from notmuch_database_remove_message, so this patch also vastly simplfies the latter using the former. This API is also useful in its own right and will be used in a later patch for eager maildir flag synchronization.
* lib: Remove message document directly after removing the last file name.Gravatar Austin Clements2011-09-23
| | | | | | | | | | | | Previously, notmuch_database_remove_message would remove the message file name, sync the change to the message document, re-find the message document, and then delete it if there were no more file names. An interruption after sync'ing would result in a file-name-less, permanently un-removable zombie message that would produce errors and odd results in searches. We could wrap this in an atomic section, but it's much simpler to eliminate the round-about approach and just delete the message document instead of sync'ing it if we removed the last filename.
* lib: Add support for nested atomic sections.Gravatar Austin Clements2011-09-23
| | | | | | | notmuch_database_t now keeps a nesting count and we only start a transaction or commit for the outermost atomic section. Introduces a new error, NOTMUCH_STATUS_UNBALANCED_ATOMIC.
* lib: Add notmuch_database_{begin,end}_atomic.Gravatar Austin Clements2011-09-23
| | | | | | These operations translate into non-flushed Xapian transactions, allowing arbitrary groups of database operations to be performed atomically.
* fix sum moar typos [comments in source code]Gravatar Pieter Praet2011-06-23
| | | | | | | | | | Various typo fixes in comments within the source code. Signed-off-by: Pieter Praet <pieter@praet.org> Edited-by: Carl Worth <cworth@cworth.org> Restricted to just source-code comments, (and fixed fix of "descriptios" to "descriptors" rather than "descriptions").
* Add a generic function to get a list of terms with some prefix.Gravatar Austin Clements2011-03-21
| | | | | | Replace _notmuch_convert_tags with this and simplify _create_filenames_for_terms_with_prefix. This will also come in handy shortly to get the message file name list.
* Implement an internal generic string list and use it.Gravatar Austin Clements2011-03-21
| | | | | | | | | | | | This replaces the guts of the filename list and tag list, making those interfaces simple iterators over the generic string list. The directory, message filename, and tags-related code now build generic string lists and then wraps them in specific iterators. The real wins come in later patches, when we use these for even more generic functionality. As a nice side-effect, this also eliminates the annoying dependency on GList in the tag list.
* Add support for folder-based searching.Gravatar Carl Worth2011-01-15
| | | | | | | | A new "folder:" prefix in the query string can now be used to match the directories in which mail files are stored. The addition of this feature causes the recently added search-by-folder tests to now pass.
* Tighten up a memory allocation.Gravatar Carl Worth2011-01-15
| | | | | | Using the local talloc context ensures that the memory we are using here will be freed shortly, (rather than hanging on for a long time with the notmuch database object).
* lib: Remove the notion of TAGS_INVALIDGravatar Carl Worth2010-11-11
| | | | | | | | This rather ugly hack was recently obviated by the removal of the notmuch_database_set_maildir_sync function. Now, clients must make explicit calls to do any syncrhonization between maildir flags and tags. So the library no longer needs to worry about doing inconsistent synchronization while a message is only partially added.
* lib: Rework interface for maildir_flags synchronizationGravatar Carl Worth2010-11-11
| | | | | | | | | | | | | Instead of having an API for setting a library-wide flag for synchronization (notmuch_database_set_maildir_sync) we instead implement maildir synchronization with two new library functions: notmuch_message_maildir_flags_to_tags and notmuch_message_tags_to_maildir_flags These functions are nicely documented here, (though the implementation does not quite match the documentation yet---as plainly evidenced by the current results of the test suite).
* Make maildir synchronization configurableGravatar Michal Sojka2010-11-10
| | | | | | | This adds group [maildir] and key 'synchronize_flags' to the configuration file. Its value enables (true) or diables (false) the synchronization between notmuch tags and maildir flags. By default, the synchronization is disabled.
* Maildir synchronizationGravatar Michal Sojka2010-11-10
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch allows bi-directional synchronization between maildir flags and certain tags. The flag-to-tag mapping is defined by flag2tag array. The synchronization works this way: 1) Whenever notmuch new is executed, the following happens: o New messages are tagged with configured new_tags. o For new or renamed messages with maildir info present in the file name, the tags defined in flag2tag are either added or removed depending on the flags from the file name. 2) Whenever notmuch tag (or notmuch restore) is executed, a new set of flags based on the tags is constructed for every message and a new file name is prepared based on the old file name but with the new flags. If the flags differs and the old message was in 'new' directory then this is replaced with 'cur' in the new file name. If the new and old file names differ, the file is renamed and notmuch database is updated accordingly. The rename happens before the database is updated. In case of crash between rename and database update, the next run of notmuch new brings the database in sync with the mail store again.
* lib: Return added message even if it already was in the databaseGravatar Michal Sojka2010-11-10
|
* lib: Eliminate some redundant includes of xapian.hGravatar Carl Worth2010-11-01
| | | | | Most files including this already include database-private.h which includes xapian.h already.
* lib: Add some missing static qualifiers.Gravatar Carl Worth2010-11-01
| | | | | | These various functions and data are all used only locally, so should be marked static. Ensuring we get these right will avoid us accidentally leaking unintended symbols through the library interface.
* lib: Fix use-after-free bug.Gravatar Carl Worth2010-09-20
| | | | | | | Thanks to the new git-based test suite, it's easy to run the whole test suite in valgrind, (simply "make test OPTIONS="--valgrind"), and doing so showed this obvious use-after-free bug, (triggered by the thread-order tests).
* Add support (and tests) for messages with really long message IDs.Gravatar Carl Worth2010-06-04
| | | | | | | | | | | | | | | | | | | | | | | Scott Henson reported an internal error that occurred when he tried to add a message that referenced another message with a message ID well over 300 characters in length. The bug here was running into a Xapian limit for the length of metadata key names, (which is even more restrictive than the Xapian limit for the length of terms). We fix this by noticing long message ID values and instead using a message ID of the form "notmuch-sha1-<sha1_sum_of_message_id>". That is, we use SHA1 to generate a compressed, (but still unique), version of the message ID. We add support to the test suite to exercise this fix. The tests add a message referencing the long message ID, then add the message with the long message ID, then finally add another message referencing the long ID. Each of these tests exercise different code paths where the special handling is implemented. A final test ensures that all three messages are stitched together into a single thread---guaranteeing that the three code paths all act consistently.
* Avoid database corruption by not adding partially-constructed mail documents.Gravatar Carl Worth2010-06-04
| | | | | | | | | | | | | | | | | Previously we were using Xapian's add_document to allocate document ID values for notmuch_message_t objects. This had the drawback of adding a partially constructed mail document to the database. If notmuch was subsequently interrupted before fully populating this document, then later runs would be quite confused when seeing the partial documents. There are reports from the wild of people hitting internal errors of the form "Message ... has no thread ID" for example, (which is currently an unrecoverable error). We fix this by manually allocating document IDs without adding documents. With this change, we never call Xapian's add_document method, but only replace_document with either the current document ID of a message or a new one that we have allocated.
* lib: Audit all notmuch_database call for Xapian exception handling.Gravatar Carl Worth2010-04-24
| | | | | | Our current approach is for top-level entry poitns in the library to have try/catch blocks that catch any Xapian exception and print a message. Add a few missing blocks and fix up the documentation.
* lib: Remove condition regarding a NULL parent_thread_id.Gravatar Carl Worth2010-04-12
| | | | | A recent change guaranteed that a message ID can never be resolved to a NULL thread ID, so we don't need this extra case.
* lib: Always add reference terms to the database.Gravatar Carl Worth2010-04-12
| | | | | | | | Previously, we were only adding the reference terms for cases where the referenced message did not yet exist in the database. For thread presentation, it's useful to have the connection information provided by the references, even when the messages are present. So add this term unconditionally.
* lib: Document the metadata stored within the Xapian database.Gravatar Carl Worth2010-04-12
| | | | | We are currently storing "version", "last_thread_id", and "thread_id_*" values so document how each of these are used.
* lib: Fix line-wrapping in _notmuch_database_link_message.Gravatar Carl Worth2010-04-12
| | | | | | This function had some excessively long lines due to nested expressions. It's simple enough to un-nest these and have readable line lengths.
* lib: Fix internal documentation of _notmuch_database_link_messageGravatar Carl Worth2010-04-12
| | | | | | This function was recently modified, (to include a metadata lookup for a message's thread ID before looking for parent/child thread IDs), but the documentation wasn't updated. Fix that.