Commit 08f4af62 authored by Sam Thursfield's avatar Sam Thursfield

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: GNOME/tracker-miners#56
parent 13948fda
...@@ -46,10 +46,7 @@ get_file_content (GFile *file, ...@@ -46,10 +46,7 @@ get_file_content (GFile *file,
gchar *text, *uri, *path; gchar *text, *uri, *path;
int fd; int fd;
/* If no content requested, return */ g_return_val_if_fail (n_bytes > 0, NULL);
if (n_bytes == 0) {
return NULL;
uri = g_file_get_uri (file); uri = g_file_get_uri (file);
...@@ -85,12 +82,20 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -85,12 +82,20 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
{ {
TrackerResource *metadata; TrackerResource *metadata;
TrackerConfig *config; TrackerConfig *config;
gchar *content; gsize n_bytes;
gchar *content = NULL;
config = tracker_main_get_config (); config = tracker_main_get_config ();
content = get_file_content (tracker_extract_info_get_file (info), n_bytes = tracker_config_get_max_bytes (config);
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); metadata = tracker_resource_new (NULL);
tracker_resource_add_uri (metadata, "rdf:type", "nfo:PlainTextDocument"); tracker_resource_add_uri (metadata, "rdf:type", "nfo:PlainTextDocument");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment