diff options
author | Carl Worth <cworth@cworth.org> | 2010-01-07 18:26:31 -0800 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-01-07 18:26:31 -0800 |
commit | 909f52bd8c4bdfa11cd3e75e3d0959e0293689bd (patch) | |
tree | 888ebc24e2b975d6c390e610c108a9e9fb4ecce9 /lib/message.cc | |
parent | 21f8fd6967c3ef8e726652bbd6944e29975508b5 (diff) |
lib: Implement versioning in the database and provide upgrade function.
The recent support for renames in the database is our first time
(since notmuch has had more than a single user) that we have a
database format change. To support smooth upgrades we now encode a
database format version number in the Xapian metadata.
Going forward notmuch will emit a warning if used to read from a
database with a newer version than it natively supports, and will
refuse to write to a database with a newer version.
The library also provides functions to query the database format
version:
notmuch_database_get_version
to ask if notmuch wants a newer version than that:
notmuch_database_needs_upgrade
and a function to actually perform that upgrade:
notmuch_database_upgrade
Diffstat (limited to 'lib/message.cc')
-rw-r--r-- | lib/message.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/message.cc b/lib/message.cc index ea9c8bd9..baeaa469 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -416,6 +416,24 @@ _notmuch_message_add_filename (notmuch_message_t *message, return NOTMUCH_STATUS_SUCCESS; } +/* Move the filename from the data field (as it was in database format + * version 0) to a file-direntry term instead (as in database format + * version 1). + */ +void +_notmuch_message_upgrade_filename_storage (notmuch_message_t *message) +{ + char *filename; + + filename = talloc_strdup (message, message->doc.get_data ().c_str ()); + if (filename && *filename != '\0') { + _notmuch_message_add_filename (message, filename); + message->doc.set_data (""); + _notmuch_message_sync (message); + } + talloc_free (filename); +} + const char * notmuch_message_get_filename (notmuch_message_t *message) { @@ -441,7 +459,10 @@ notmuch_message_get_filename (notmuch_message_t *message) { /* A message document created by an old version of notmuch * (prior to rename support) will have the filename in the - * data of the document rather than as a file-direntry term. */ + * data of the document rather than as a file-direntry term. + * + * It would be nice to do the upgrade of the document directly + * here, but the database is likely open in read-only mode. */ const char *data; data = message->doc.get_data ().c_str (); |