dovecot-2.2: fts: If fts-parser fails, stop indexing instead of ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Mar 13 14:04:57 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/f409deb63c40
changeset: 18345:f409deb63c40
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 13 16:04:01 2015 +0200
description:
fts: If fts-parser fails, stop indexing instead of ignoring the error and continuing.
This is especially important in case there's just some temporary error.

diffstat:

 src/plugins/fts/fts-build-mail.c    |   5 +++--
 src/plugins/fts/fts-parser-html.c   |   3 ++-
 src/plugins/fts/fts-parser-script.c |   4 +++-
 src/plugins/fts/fts-parser-tika.c   |  10 +++++++++-
 src/plugins/fts/fts-parser.c        |   6 ++++--
 src/plugins/fts/fts-parser.h        |   4 ++--
 6 files changed, 23 insertions(+), 9 deletions(-)

diffs (141 lines):

diff -r d592417ec815 -r f409deb63c40 src/plugins/fts/fts-build-mail.c
--- a/src/plugins/fts/fts-build-mail.c	Fri Mar 13 15:06:10 2015 +0200
+++ b/src/plugins/fts/fts-build-mail.c	Fri Mar 13 16:04:01 2015 +0200
@@ -260,7 +260,8 @@
 		}
 	} while (block.size > 0);
 
-	fts_parser_deinit(&ctx->body_parser);
+	if (fts_parser_deinit(&ctx->body_parser) < 0)
+		ret = -1;
 	return ret;
 }
 
@@ -366,7 +367,7 @@
 		if (ret == 0)
 			ret = fts_body_parser_finish(&ctx);
 		else
-			fts_parser_deinit(&ctx.body_parser);
+			(void)fts_parser_deinit(&ctx.body_parser);
 	}
 	if (ret == 0 && body_part && !skip_body && !body_added) {
 		/* make sure body is added even when it doesn't exist */
diff -r d592417ec815 -r f409deb63c40 src/plugins/fts/fts-parser-html.c
--- a/src/plugins/fts/fts-parser-html.c	Fri Mar 13 15:06:10 2015 +0200
+++ b/src/plugins/fts/fts-parser-html.c	Fri Mar 13 16:04:01 2015 +0200
@@ -47,13 +47,14 @@
 	block->size = parser->output->used;
 }
 
-static void fts_parser_html_deinit(struct fts_parser *_parser)
+static int fts_parser_html_deinit(struct fts_parser *_parser)
 {
 	struct html_fts_parser *parser = (struct html_fts_parser *)_parser;
 
 	mail_html2text_deinit(&parser->html2text);
 	buffer_free(&parser->output);
 	i_free(parser);
+	return 0;
 }
 
 struct fts_parser_vfuncs fts_parser_html = {
diff -r d592417ec815 -r f409deb63c40 src/plugins/fts/fts-parser-script.c
--- a/src/plugins/fts/fts-parser-script.c	Fri Mar 13 15:06:10 2015 +0200
+++ b/src/plugins/fts/fts-parser-script.c	Fri Mar 13 16:04:01 2015 +0200
@@ -254,14 +254,16 @@
 	}
 }
 
-static void fts_parser_script_deinit(struct fts_parser *_parser)
+static int fts_parser_script_deinit(struct fts_parser *_parser)
 {
 	struct script_fts_parser *parser = (struct script_fts_parser *)_parser;
+	int ret = parser->failed ? -1 : 0;
 
 	if (close(parser->fd) < 0)
 		i_error("close(%s) failed: %m", parser->path);
 	i_free(parser->path);
 	i_free(parser);
+	return ret;
 }
 
 struct fts_parser_vfuncs fts_parser_script = {
diff -r d592417ec815 -r f409deb63c40 src/plugins/fts/fts-parser-tika.c
--- a/src/plugins/fts/fts-parser-tika.c	Fri Mar 13 15:06:10 2015 +0200
+++ b/src/plugins/fts/fts-parser-tika.c	Fri Mar 13 16:04:01 2015 +0200
@@ -194,12 +194,19 @@
 	} else {
 		/* finished */
 		i_assert(ret == -1);
+		if (parser->payload->stream_errno != 0) {
+			i_error("read(%s) failed: %s",
+				i_stream_get_name(parser->payload),
+				i_stream_get_error(parser->payload));
+			parser->failed = TRUE;
+		}
 	}
 }
 
-static void fts_parser_tika_deinit(struct fts_parser *_parser)
+static int fts_parser_tika_deinit(struct fts_parser *_parser)
 {
 	struct tika_fts_parser *parser = (struct tika_fts_parser *)_parser;
+	int ret = parser->failed ? -1 : 0;
 
 	if (parser->ioloop != NULL) {
 		io_remove(&parser->io);
@@ -212,6 +219,7 @@
 	if (parser->http_req != NULL)
 		http_client_request_abort(&parser->http_req);
 	i_free(parser);
+	return ret;
 }
 
 static void fts_parser_tika_unload(void)
diff -r d592417ec815 -r f409deb63c40 src/plugins/fts/fts-parser.c
--- a/src/plugins/fts/fts-parser.c	Fri Mar 13 15:06:10 2015 +0200
+++ b/src/plugins/fts/fts-parser.c	Fri Mar 13 16:04:01 2015 +0200
@@ -83,18 +83,20 @@
 	}
 }
 
-void fts_parser_deinit(struct fts_parser **_parser)
+int fts_parser_deinit(struct fts_parser **_parser)
 {
 	struct fts_parser *parser = *_parser;
+	int ret = 0;
 
 	*_parser = NULL;
 
 	if (parser->utf8_output != NULL)
 		buffer_free(&parser->utf8_output);
 	if (parser->v.deinit != NULL)
-		parser->v.deinit(parser);
+		ret = parser->v.deinit(parser);
 	else
 		i_free(parser);
+	return ret;
 }
 
 void fts_parsers_unload(void)
diff -r d592417ec815 -r f409deb63c40 src/plugins/fts/fts-parser.h
--- a/src/plugins/fts/fts-parser.h	Fri Mar 13 15:06:10 2015 +0200
+++ b/src/plugins/fts/fts-parser.h	Fri Mar 13 16:04:01 2015 +0200
@@ -9,7 +9,7 @@
 				       const char *content_type,
 				       const char *content_disposition);
 	void (*more)(struct fts_parser *parser, struct message_block *block);
-	void (*deinit)(struct fts_parser *parser);
+	int (*deinit)(struct fts_parser *parser);
 	void (*unload)(void);
 };
 
@@ -31,7 +31,7 @@
    finished, it's still called with incoming size=0 while the parser increases
    it to non-zero. */
 void fts_parser_more(struct fts_parser *parser, struct message_block *block);
-void fts_parser_deinit(struct fts_parser **parser);
+int fts_parser_deinit(struct fts_parser **parser);
 
 void fts_parsers_unload(void);
 


More information about the dovecot-cvs mailing list