]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-insert.c
cli/insert: delay database open until after writing mail file
[notmuch] / notmuch-insert.c
index 131f09e2c6cf61139319296a28d8d8d0df566167..862da8892df78ce3ef8587d90e41b299befe274f 100644 (file)
@@ -532,19 +532,19 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     action.sa_flags = 0;
     sigaction (SIGINT, &action, NULL);
 
-    if (notmuch_database_open (notmuch_config_get_database_path (config),
-                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
-       return EXIT_FAILURE;
-
-    notmuch_exit_if_unmatched_db_uuid (notmuch);
-
     /* Write the message to the Maildir new directory. */
     newpath = maildir_write_new (config, STDIN_FILENO, maildir);
     if (! newpath) {
-       notmuch_database_destroy (notmuch);
        return EXIT_FAILURE;
     }
 
+   if (notmuch_database_open (notmuch_config_get_database_path (config),
+                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
+       return EXIT_FAILURE;
+
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
+
     /* Index the message. */
     status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);