class NotmuchCompactor : public Xapian::Compactor
{
notmuch_compact_status_cb_t status_cb;
+ void *status_closure;
public:
- NotmuchCompactor(notmuch_compact_status_cb_t cb) : status_cb(cb) { }
+ NotmuchCompactor(notmuch_compact_status_cb_t cb, void *closure) :
+ status_cb(cb), status_closure(closure) { }
virtual void
set_status (const std::string &table, const std::string &status)
return;
}
- status_cb(msg);
+ status_cb(msg, status_closure);
talloc_free(msg);
}
};
notmuch_status_t
notmuch_database_compact (const char* path,
const char* backup_path,
- notmuch_compact_status_cb_t status_cb)
+ notmuch_compact_status_cb_t status_cb,
+ void *closure)
{
void *local;
char *notmuch_path, *xapian_path, *compact_xapian_path;
- char *old_xapian_path = NULL;
notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
notmuch_database_t *notmuch = NULL;
struct stat statbuf;
}
if (backup_path != NULL) {
- if (! (old_xapian_path = talloc_asprintf (local, "%s/xapian.old", backup_path))) {
- ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
- goto DONE;
- }
-
- if (stat(old_xapian_path, &statbuf) != -1) {
- fprintf (stderr, "Backup path already exists: %s\n", old_xapian_path);
+ if (stat(backup_path, &statbuf) != -1) {
+ fprintf (stderr, "Backup path already exists: %s\n", backup_path);
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
}
try {
- NotmuchCompactor compactor(status_cb);
+ NotmuchCompactor compactor(status_cb, closure);
compactor.set_renumber(false);
compactor.add_source(xapian_path);
goto DONE;
}
- if (old_xapian_path != NULL) {
- if (rename(xapian_path, old_xapian_path)) {
+ if (backup_path) {
+ if (rename(xapian_path, backup_path)) {
fprintf (stderr, "Error moving old database out of the way\n");
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
goto DONE;
}
- notmuch_database_close(notmuch);
-
DONE:
+ if (notmuch)
+ notmuch_database_destroy (notmuch);
+
talloc_free(local);
+
return ret;
}
#else
notmuch_status_t
notmuch_database_compact (unused (const char* path),
unused (const char* backup_path),
- unused (notmuch_compact_status_cb_t status_cb))
+ unused (notmuch_compact_status_cb_t status_cb),
+ unused (void *closure))
{
fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");
return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;