aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-12-23 23:37:41 -0400
committerDavid Bremner <david@tethera.net>2021-02-06 19:34:17 -0400
commit5232462dcfe77e6af475c9dd1a25513c43af53f3 (patch)
tree36a15d457bc86f5b3057d2738b6d2cd6d0cf379f /lib/database.cc
parent87e3a82feb3932fea2c2b160c73d210dcd48a78c (diff)
lib: split notmuch_database_compact
The "back end" function takes an open notmuch database, which should know its own path (i.e. the path needs to be cached in the configuration data).
Diffstat (limited to 'lib/database.cc')
-rw-r--r--lib/database.cc42
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/database.cc b/lib/database.cc
index 0f4e2ff9..650359f4 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -705,27 +705,51 @@ notmuch_database_compact (const char *path,
notmuch_compact_status_cb_t status_cb,
void *closure)
{
- void *local;
- char *notmuch_path, *xapian_path, *compact_xapian_path;
notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
notmuch_database_t *notmuch = NULL;
- struct stat statbuf;
- bool keep_backup;
char *message = NULL;
- local = talloc_new (NULL);
- if (! local)
- return NOTMUCH_STATUS_OUT_OF_MEMORY;
-
ret = notmuch_database_open_verbose (path,
NOTMUCH_DATABASE_MODE_READ_WRITE,
&notmuch,
&message);
if (ret) {
if (status_cb) status_cb (message, closure);
- goto DONE;
+ return ret;
}
+ _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path);
+
+ return notmuch_database_compact_db (notmuch,
+ backup_path,
+ status_cb,
+ closure);
+}
+
+notmuch_status_t
+notmuch_database_compact_db (notmuch_database_t *notmuch,
+ const char *backup_path,
+ notmuch_compact_status_cb_t status_cb,
+ void *closure) {
+ void *local;
+ char *notmuch_path, *xapian_path, *compact_xapian_path;
+ const char* path;
+ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
+ struct stat statbuf;
+ bool keep_backup;
+
+ ret = _notmuch_database_ensure_writable (notmuch);
+ if (ret)
+ return ret;
+
+ path = notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH);
+ if (! path)
+ return NOTMUCH_STATUS_PATH_ERROR;
+
+ local = talloc_new (NULL);
+ if (! local)
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;