[PATCH 10/11] cli/insert: require succesful message indexing for success status
Jani Nikula
jani at nikula.org
Mon Sep 22 02:55:01 PDT 2014
Add --keep option to keep any remaining stuff in index or file. We
could distinguish between failures to index and failures to apply tags
or maildir sync, but for simplicity just have one.
---
notmuch-insert.c | 20 +++++++++++++++-----
test/T070-insert.sh | 2 +-
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 80f52d4..f27b9cb 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -433,6 +433,7 @@ DONE:
int
notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
{
+ notmuch_status_t status;
notmuch_database_t *notmuch;
struct sigaction action;
const char *db_path;
@@ -442,6 +443,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
char *query_string = NULL;
const char *folder = NULL;
notmuch_bool_t create_folder = FALSE;
+ notmuch_bool_t keep = FALSE;
notmuch_bool_t synchronize_flags;
const char *maildir;
char *newpath;
@@ -451,6 +453,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
{ NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
+ { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },
{ NOTMUCH_OPT_END, 0, 0, 0, 0 }
};
@@ -525,11 +528,18 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
return EXIT_FAILURE;
}
- /* Add the message to the index.
- * Even if adding the message to the notmuch database fails,
- * the message is on disk and we consider the delivery completed. */
- add_file (notmuch, newpath, tag_ops, synchronize_flags, TRUE);
+ /* Index the message. */
+ status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);
+ if (status) {
+ if (keep) {
+ status = NOTMUCH_STATUS_SUCCESS;
+ } else {
+ /* If maildir flag sync failed, this might fail. */
+ unlink (newpath);
+ }
+ }
notmuch_database_destroy (notmuch);
- return EXIT_SUCCESS;
+
+ return status ? EXIT_FAILURE : EXIT_SUCCESS;
}
diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index ea9db07..aacc643 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -23,7 +23,7 @@ test_expect_code 1 "Insert zero-length file" \
# This test is a proxy for other errors that may occur while trying to
# add a message to the notmuch database, e.g. database locked.
-test_expect_code 0 "Insert non-message" \
+test_expect_code 1 "Insert non-message" \
"echo bad_message | notmuch insert"
test_begin_subtest "Database empty so far"
--
1.7.2.5
More information about the notmuch
mailing list