From: Jani Nikula <jani@nikula.org>
To: David Bremner <david@tethera.net>, Jani Nikula <jani@nikula.org>,
Paul Wise <pabs@debian.org>,
notmuch@notmuchmail.org
Subject: [PATCH v2] cli: consider files vanishing during notmuch new non-fatal
Date: Mon, 21 Nov 2016 22:14:33 +0200 [thread overview]
Message-ID: <1479759273-18010-1-git-send-email-jani@nikula.org> (raw)
In-Reply-To: <87shqrwsye.fsf@tethera.net>
If some software other than notmuch new renames or removes files
during the notmuch new scan (specifically after scandir but before
indexing the file), keep going instead of bailing out. Failing to
index the file is just a race condition between notmuch and the other
software; the rename could happen after the notmuch new scan
anyway. It's not fatal, and we'll catch the renamed files on the next
scan.
Add a new exit code for when files vanished, so the caller has a
chance to detect the race and re-run notmuch new to recover.
Reported by Paul Wise <pabs@debian.org> at
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=843127
---
v2: use EX_TEMPFAIL status code
---
notmuch-client.h | 11 +++++++++++
notmuch-new.c | 15 ++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/notmuch-client.h b/notmuch-client.h
index 9ce2aef17431..793f32ecc55a 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -25,6 +25,7 @@
#define _GNU_SOURCE /* for getline */
#endif
#include <stdio.h>
+#include <sysexits.h>
#include "compat.h"
@@ -114,6 +115,16 @@ chomp_newline (char *str)
str[strlen(str)-1] = '\0';
}
+/* Exit status code indicating temporary failure; user is invited to
+ * retry.
+ *
+ * For example, file(s) in the mail store were removed or renamed
+ * after notmuch new scanned the directories but before indexing the
+ * file(s). If the file was renamed, the indexing might not be
+ * complete, and the user is advised to re-run notmuch new.
+ */
+#define NOTMUCH_EXIT_TEMPFAIL EX_TEMPFAIL
+
/* Exit status code indicating the requested format version is too old
* (support for that version has been dropped). CLI code should use
* notmuch_exit_if_unsupported_format rather than directly exiting
diff --git a/notmuch-new.c b/notmuch-new.c
index c55dea7bc1b7..cc680b412a45 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -53,6 +53,7 @@ typedef struct {
int total_files;
int processed_files;
int added_messages, removed_messages, renamed_messages;
+ int vanished_files;
struct timeval tv_start;
_filename_list_t *removed_files;
@@ -280,11 +281,13 @@ add_file (notmuch_database_t *notmuch, const char *filename,
case NOTMUCH_STATUS_FILE_NOT_EMAIL:
fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename);
break;
- /* Fatal issues. Don't process anymore. */
case NOTMUCH_STATUS_FILE_ERROR:
+ /* Someone renamed/removed the file between scandir and now. */
+ state->vanished_files++;
fprintf (stderr, "Unexpected error with file %s\n", filename);
(void) print_status_database ("add_file", notmuch, status);
- goto DONE;
+ break;
+ /* Fatal issues. Don't process anymore. */
case NOTMUCH_STATUS_READ_ONLY_DATABASE:
case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
case NOTMUCH_STATUS_OUT_OF_MEMORY:
@@ -1151,5 +1154,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
if (!no_hooks && !ret && !interrupted)
ret = notmuch_run_hook (db_path, "post-new");
- return ret || interrupted ? EXIT_FAILURE : EXIT_SUCCESS;
+ if (ret || interrupted)
+ return EXIT_FAILURE;
+
+ if (add_files_state.vanished_files)
+ return NOTMUCH_EXIT_TEMPFAIL;
+
+ return EXIT_SUCCESS;
}
--
2.1.4
next prev parent reply other threads:[~2016-11-21 20:16 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-04 12:46 [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`? David Bremner
2016-11-04 16:26 ` David Bremner
2016-11-13 1:51 ` Austin Clements
2016-11-14 18:44 ` J. Lewis Muir
2016-11-14 18:59 ` David Bremner
2016-11-04 18:47 ` Jani Nikula
2016-11-05 2:15 ` Paul Wise
2016-11-05 12:57 ` [PATCH] cli: consider files vanishing during notmuch new non-fatal Jani Nikula
2016-11-05 13:22 ` Paul Wise
2016-11-12 15:39 ` David Bremner
2016-11-12 16:04 ` Brian Sniffen
2016-11-12 16:10 ` David Bremner
2016-11-12 16:15 ` David Bremner
2016-11-12 21:08 ` Brian Sniffen
2016-11-12 21:36 ` David Bremner
2016-11-12 20:35 ` Jani Nikula
2016-11-16 11:43 ` David Bremner
2016-11-21 20:14 ` Jani Nikula [this message]
2016-11-26 2:44 ` [PATCH] cli/new: document new exit code David Bremner
2016-11-26 9:17 ` Jani Nikula
2016-11-26 9:18 ` [PATCH] test: check the handling of files vanishing between scandir and indexing Jani Nikula
2016-11-27 9:59 ` [PATCH v2] " Jani Nikula
2016-11-29 2:16 ` David Bremner
2016-11-29 7:31 ` Tomi Ollila
2016-12-03 11:24 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1479759273-18010-1-git-send-email-jani@nikula.org \
--to=jani@nikula.org \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
--cc=pabs@debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).