]> git.cworth.org Git - notmuch/blobdiff - notmuch-restore.c
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / notmuch-restore.c
index 4b509d95ba003dd4342d2bd74ed47c67d4bca6d8..1cce004a06d4dd8b0d8a402474a771c94e8fe155 100644 (file)
@@ -219,9 +219,8 @@ parse_sup_line (void *ctx, char *line,
 }
 
 int
-notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
+notmuch_restore_command (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;
@@ -237,12 +236,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
     int opt_index;
     int include = 0;
     int input_format = DUMP_FORMAT_AUTO;
-
-    if (notmuch_database_open (notmuch_config_get_database_path (config),
-                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
+    int errnum;
+    notmuch_bool_t synchronize_flags;
+
+    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[] = {
@@ -268,8 +272,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
        goto DONE;
     }
 
-    notmuch_process_shared_options (argv[0]);
-    notmuch_exit_if_unmatched_db_uuid (notmuch);
+    notmuch_process_shared_options (notmuch, argv[0]);
 
     if (include == 0) {
        include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_PROPERTIES | DUMP_INCLUDE_TAGS;
@@ -309,7 +312,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
        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;
@@ -339,7 +342,8 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
            if (ret)
                goto DONE;
        }
-       if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') {
+       if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] ==
+           '=') {
            ret = process_properties_line (notmuch, line + 2);
            if (ret)
                goto DONE;
@@ -356,6 +360,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
     }
 
     char *p;
+
     for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {
        if (*p == '(')
            input_format = DUMP_FORMAT_SUP;
@@ -376,9 +381,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
        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] == '=') {
+       if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] ==
+           '=') {
            ret = process_properties_line (notmuch, line + 2);
            if (ret)
                goto DONE;
@@ -448,10 +454,13 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
     if (notmuch)
        notmuch_database_destroy (notmuch);
 
-    if (input && gzclose_r (input)) {
-       fprintf (stderr, "Error closing %s: %s\n",
-                name_for_error, gzerror (input, NULL));
-       ret = EXIT_FAILURE;
+    if (input) {
+       errnum = gzclose_r (input);
+       if (errnum) {
+           fprintf (stderr, "Error closing %s: %d\n",
+                    name_for_error, errnum);
+           ret = EXIT_FAILURE;
+       }
     }
 
     return ret ? EXIT_FAILURE : EXIT_SUCCESS;