aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/directory.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2010-01-07 10:19:44 -0800
committerGravatar Carl Worth <cworth@cworth.org>2010-01-07 10:19:44 -0800
commitf93b7218c3e2d11c5b3cdd4c367a42ca7a7ede77 (patch)
tree7d1cd35cb6e21d2c1dbf3bf79799fbeb35ae6422 /lib/directory.cc
parent6ed606c19edfe06d2dfd48854fc97f8502eaaf7c (diff)
lib: Consolidate checks for read-only database.
Previously, many checks were deep in the library just before a cast operation. These have now been replaced with internal errors and new checks have instead been added at the beginning of all top-levelentry points requiring a read-write database. The new checks now also use a single function for checking and printing the error message. This will give us a convenient location to extend the check, (such as based on database version as well).
Diffstat (limited to 'lib/directory.cc')
-rw-r--r--lib/directory.cc15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/directory.cc b/lib/directory.cc
index d5015e0a..461c0cc3 100644
--- a/lib/directory.cc
+++ b/lib/directory.cc
@@ -182,11 +182,8 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
path = _notmuch_database_relative_path (notmuch, path);
- if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
- fprintf (stderr, "Attempted to update a read-only database.\n");
- *status_ret = NOTMUCH_STATUS_READONLY_DATABASE;
- return NULL;
- }
+ if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
+ INTERNAL_ERROR ("Failure to ensure database is writable");
db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
@@ -268,11 +265,11 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,
{
notmuch_database_t *notmuch = directory->notmuch;
Xapian::WritableDatabase *db;
+ notmuch_status_t status;
- if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
- fprintf (stderr, "Attempted to update a read-only database.\n");
- return NOTMUCH_STATUS_READONLY_DATABASE;
- }
+ status = _notmuch_database_ensure_writable (notmuch);
+ if (status)
+ return status;
db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);