]> git.notmuchmail.org Git - notmuch/commitdiff
CLI/restore: convert to new config framework
authorDavid Bremner <david@tethera.net>
Mon, 5 Oct 2020 23:28:29 +0000 (20:28 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 6 Feb 2021 23:15:53 +0000 (19:15 -0400)
Switch one configuration check to new n_c_get_bool function, and
switch use of config as talloc context to notmuch.

notmuch-restore.c
notmuch.c
test/T035-read-config.sh

index 544f422802d15502b1ab2e73e69e976833a5a549..ce07f89d927931e1dbb570197e27fb61ccb96ce1 100644 (file)
@@ -219,9 +219,8 @@ parse_sup_line (void *ctx, char *line,
 }
 
 int
-notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[])
+notmuch_restore_command (unused(notmuch_config_t *config), notmuch_database_t *notmuch, int argc, char *argv[])
 {
-    notmuch_database_t *notmuch;
     bool accumulate = false;
     tag_op_flag_t flags = 0;
     tag_op_list_t *tag_ops;
@@ -238,12 +237,16 @@ notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *no
     int include = 0;
     int input_format = DUMP_FORMAT_AUTO;
     int errnum;
+    notmuch_bool_t synchronize_flags;
 
-    if (notmuch_database_open (notmuch_config_get_database_path (config),
-                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
+    if (print_status_database (
+           "notmuch restore",
+           notmuch,
+           notmuch_config_get_bool (notmuch, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS,
+                                    &synchronize_flags)))
        return EXIT_FAILURE;
 
-    if (notmuch_config_get_maildir_synchronize_flags (config))
+    if (synchronize_flags)
        flags |= TAG_FLAG_MAILDIR_SYNC;
 
     notmuch_opt_desc_t options[] = {
@@ -310,7 +313,7 @@ notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *no
        goto DONE;
     }
 
-    tag_ops = tag_op_list_create (config);
+    tag_ops = tag_op_list_create (notmuch);
     if (tag_ops == NULL) {
        fprintf (stderr, "Out of memory.\n");
        ret = EXIT_FAILURE;
@@ -377,7 +380,7 @@ notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *no
        if (line_ctx != NULL)
            talloc_free (line_ctx);
 
-       line_ctx = talloc_new (config);
+       line_ctx = talloc_new (notmuch);
 
        if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') {
            ret = process_properties_line (notmuch, line + 2);
index b10cc7029c110dacd7ba14db62801710a11e60b1..4258ed43a0c01c152bf27924f3b35ddee968d878 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -161,7 +161,7 @@ static command_t commands[] = {
       "Add/remove tags for all messages matching the search terms." },
     { "dump", notmuch_dump_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE,
       "Create a plain-text dump of the tags for each message." },
-    { "restore", notmuch_restore_command, NOTMUCH_COMMAND_CONFIG_OPEN,
+    { "restore", notmuch_restore_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE,
       "Restore the tags from the given dump file (see 'dump')." },
     { "compact", notmuch_compact_command, NOTMUCH_COMMAND_CONFIG_OPEN,
       "Compact the notmuch database." },
index 9e506dfad1f8119c0514951dd7ef2ab5ab4e13c0..35fbd60043a1b3fa00288052400ac0624f88ad75 100755 (executable)
@@ -122,4 +122,24 @@ notmuch dump --include=tags query:$query_name | sort >> OUTPUT
 restore_config
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "restore with xdg config"
+backup_config
+notmuch dump '*' > EXPECTED
+notmuch tag -inbox '*'
+xdg_config
+notmuch restore --input=EXPECTED
+notmuch dump > OUTPUT
+restore_config
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "restore with xdg+profile config"
+backup_config
+notmuch dump '*' > EXPECTED
+notmuch tag -inbox '*'
+xdg_config work
+notmuch restore --input=EXPECTED
+notmuch dump > OUTPUT
+restore_config
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done