mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
lib: add closure parameter to compact status update callback
This provides much more flexibility for the caller.
This commit is contained in:
parent
35ca5feb28
commit
180dba66e4
3 changed files with 15 additions and 12 deletions
|
@ -821,9 +821,11 @@ static int rmtree (const char *path)
|
||||||
class NotmuchCompactor : public Xapian::Compactor
|
class NotmuchCompactor : public Xapian::Compactor
|
||||||
{
|
{
|
||||||
notmuch_compact_status_cb_t status_cb;
|
notmuch_compact_status_cb_t status_cb;
|
||||||
|
void *status_closure;
|
||||||
|
|
||||||
public:
|
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
|
virtual void
|
||||||
set_status (const std::string &table, const std::string &status)
|
set_status (const std::string &table, const std::string &status)
|
||||||
|
@ -842,7 +844,7 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_cb(msg);
|
status_cb(msg, status_closure);
|
||||||
talloc_free(msg);
|
talloc_free(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -861,7 +863,8 @@ public:
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_compact (const char* path,
|
notmuch_database_compact (const char* path,
|
||||||
const char* backup_path,
|
const char* backup_path,
|
||||||
notmuch_compact_status_cb_t status_cb)
|
notmuch_compact_status_cb_t status_cb,
|
||||||
|
void *closure)
|
||||||
{
|
{
|
||||||
void *local;
|
void *local;
|
||||||
char *notmuch_path, *xapian_path, *compact_xapian_path;
|
char *notmuch_path, *xapian_path, *compact_xapian_path;
|
||||||
|
@ -913,7 +916,7 @@ notmuch_database_compact (const char* path,
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
NotmuchCompactor compactor(status_cb);
|
NotmuchCompactor compactor(status_cb, closure);
|
||||||
|
|
||||||
compactor.set_renumber(false);
|
compactor.set_renumber(false);
|
||||||
compactor.add_source(xapian_path);
|
compactor.add_source(xapian_path);
|
||||||
|
@ -953,7 +956,8 @@ DONE:
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_compact (unused (const char* path),
|
notmuch_database_compact (unused (const char* path),
|
||||||
unused (const char* backup_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");
|
fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");
|
||||||
return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
|
return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
|
||||||
|
|
|
@ -219,7 +219,7 @@ notmuch_database_close (notmuch_database_t *database);
|
||||||
/* A callback invoked by notmuch_database_compact to notify the user
|
/* A callback invoked by notmuch_database_compact to notify the user
|
||||||
* of the progress of the compaction process.
|
* of the progress of the compaction process.
|
||||||
*/
|
*/
|
||||||
typedef void (*notmuch_compact_status_cb_t)(const char*);
|
typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure);
|
||||||
|
|
||||||
/* Compact a notmuch database, backing up the original database to the
|
/* Compact a notmuch database, backing up the original database to the
|
||||||
* given path.
|
* given path.
|
||||||
|
@ -231,7 +231,8 @@ typedef void (*notmuch_compact_status_cb_t)(const char*);
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_compact (const char* path,
|
notmuch_database_compact (const char* path,
|
||||||
const char* backup_path,
|
const char* backup_path,
|
||||||
notmuch_compact_status_cb_t status_cb);
|
notmuch_compact_status_cb_t status_cb,
|
||||||
|
void *closure);
|
||||||
|
|
||||||
/* Destroy the notmuch database, closing it if necessary and freeing
|
/* Destroy the notmuch database, closing it if necessary and freeing
|
||||||
* all associated resources.
|
* all associated resources.
|
||||||
|
|
|
@ -20,10 +20,8 @@
|
||||||
|
|
||||||
#include "notmuch-client.h"
|
#include "notmuch-client.h"
|
||||||
|
|
||||||
void status_update_cb (const char *msg);
|
static void
|
||||||
|
status_update_cb (const char *msg, unused (void *closure))
|
||||||
void
|
|
||||||
status_update_cb (const char *msg)
|
|
||||||
{
|
{
|
||||||
printf("%s\n", msg);
|
printf("%s\n", msg);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +36,7 @@ notmuch_compact_command (notmuch_config_t *config,
|
||||||
notmuch_status_t ret;
|
notmuch_status_t ret;
|
||||||
|
|
||||||
printf ("Compacting database...\n");
|
printf ("Compacting database...\n");
|
||||||
ret = notmuch_database_compact (path, backup_path, status_update_cb);
|
ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string(ret));
|
fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string(ret));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue