diff options
| author | David Bremner <david@tethera.net> | 2015-04-06 07:39:55 +0900 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2015-08-14 18:23:49 +0200 |
| commit | f76d8f82dd004cf14426a91e8a80dcd2a4b97317 (patch) | |
| tree | b2a08fb89242d809d095665a84ff75c6d7d142e3 /notmuch.c | |
| parent | 5a3b42fb8c556397841b86c5fda1c4554dab253a (diff) | |
cli: add global option "--uuid"
The function notmuch_exit_if_unmatched_db_uuid is split from
notmuch_process_shared_options because it needs an open notmuch
database.
There are two exceptional cases in uuid handling.
1) notmuch config and notmuch setup don't currently open the database,
so it doesn't make sense to check the UUID.
2) notmuch compact opens the database inside the library, so we either
need to open the database just to check uuid, or change the API.
Diffstat (limited to 'notmuch.c')
| -rw-r--r-- | notmuch.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -47,10 +47,12 @@ static int _help_for (const char *topic); static notmuch_bool_t print_version = FALSE, print_help = FALSE; +char *notmuch_requested_db_uuid = NULL; const notmuch_opt_desc_t notmuch_shared_options [] = { { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 }, { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 }, + { NOTMUCH_OPT_STRING, ¬much_requested_db_uuid, "uuid", 'u', 0 }, {0, 0, 0, 0, 0} }; @@ -218,6 +220,22 @@ be supported in the future.\n", notmuch_format_version); } } +void +notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch) +{ + const char *uuid = NULL; + + if (!notmuch_requested_db_uuid) + return; + IGNORE_RESULT (notmuch_database_get_revision (notmuch, &uuid)); + + if (strcmp (notmuch_requested_db_uuid, uuid) != 0){ + fprintf (stderr, "Error: requested database revision %s does not match %s\n", + notmuch_requested_db_uuid, uuid); + exit (1); + } +} + static void exec_man (const char *page) { |
