[tracker-miners/sam/text-extractor-errors] tracker-extract-text: Correctly report errors back to the caller
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/text-extractor-errors] tracker-extract-text: Correctly report errors back to the caller
- Date: Wed, 1 May 2019 14:10:24 +0000 (UTC)
commit 08f4af627fa01cdaca294cb1b346f22814ea2826
Author: Sam Thursfield <sam afuera me uk>
Date: Wed May 1 15:54:39 2019 +0200
tracker-extract-text: Correctly report errors back to the caller
The tracker_extract_get_metadata() function should return FALSE if
an error occurs reading the file. The tracker-extract-text module would
return TRUE in all cases.
This was causing intermittent failures in the functional-tests, as the
following situation could occur:
1. file2.txt is created
2. tracker-miner-fs sees file2.txt and processes it
3. file2.txt is deleted (or moved into an unmonitored directory)
4. tracker-miner-fs sees the deletion and removes its resource from
the store
5. tracker-extract sees the created notification for file2.txt and
tries to process it
6. the tracker_extract_get_metadata() incorrectly returns TRUE
(success), so tracker-extract recreates the deleted resource
This problem was being detected in the functional tests and was
causing intermittent failures.
This hopefully fixes: https://gitlab.gnome.org/GNOME/tracker-miners/issues/56
src/tracker-extract/tracker-extract-text.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-text.c b/src/tracker-extract/tracker-extract-text.c
index 5f94d7309..a75909bfd 100644
--- a/src/tracker-extract/tracker-extract-text.c
+++ b/src/tracker-extract/tracker-extract-text.c
@@ -46,10 +46,7 @@ get_file_content (GFile *file,
gchar *text, *uri, *path;
int fd;
- /* If no content requested, return */
- if (n_bytes == 0) {
- return NULL;
- }
+ g_return_val_if_fail (n_bytes > 0, NULL);
uri = g_file_get_uri (file);
@@ -85,12 +82,20 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
{
TrackerResource *metadata;
TrackerConfig *config;
- gchar *content;
+ gsize n_bytes;
+ gchar *content = NULL;
config = tracker_main_get_config ();
- content = get_file_content (tracker_extract_info_get_file (info),
- tracker_config_get_max_bytes (config));
+ n_bytes = tracker_config_get_max_bytes (config);
+ if (n_bytes > 0) {
+ content = get_file_content (tracker_extract_info_get_file (info), n_bytes);
+
+ if (content == NULL) {
+ /* An error occurred, perhaps the file was deleted. */
+ return FALSE;
+ }
+ }
metadata = tracker_resource_new (NULL);
tracker_resource_add_uri (metadata, "rdf:type", "nfo:PlainTextDocument");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]