Commit 91e6b2f2 authored by Carlos Garnacho's avatar Carlos Garnacho

libtracker-miner: Add notifier query to check for file existence

When handling a move event, the miner checks that the source file existed
previously by checking the information element URN. Add an extra file
notifier query that checks the nfo:FileDataObject existence in the
tracker:FileSystem graph instead.

This avoids having to poke every other graph in order to get this URN.
parent 9c142796
......@@ -83,6 +83,7 @@ typedef struct {
TrackerSparqlStatement *content_query;
TrackerSparqlStatement *urn_query;
TrackerSparqlStatement *exists_query;
GTimer *timer;
......@@ -711,6 +712,30 @@ sparql_urn_ensure_statement (TrackerFileNotifier *notifier,
return priv->urn_query;
static TrackerSparqlStatement *
sparql_exists_ensure_statement (TrackerFileNotifier *notifier,
GError **error)
TrackerFileNotifierPrivate *priv;
priv = tracker_file_notifier_get_instance_private (notifier);
if (priv->exists_query)
return priv->exists_query;
priv->exists_query =
tracker_sparql_connection_query_statement (priv->connection,
"ASK "
" GRAPH tracker:FileSystem {"
" ~file a nfo:FileDataObject ."
" }"
return priv->exists_query;
static void
query_execute_cb (TrackerSparqlStatement *statement,
GAsyncResult *res,
......@@ -1526,6 +1551,7 @@ tracker_file_notifier_finalize (GObject *object)
g_clear_object (&priv->content_query);
g_clear_object (&priv->urn_query);
g_clear_object (&priv->exists_query);
g_object_unref (priv->crawler);
g_object_unref (priv->monitor);
......@@ -1943,6 +1969,66 @@ tracker_file_notifier_get_file_iri (TrackerFileNotifier *notifier,
return iri;
tracker_file_notifier_query_file_exists (TrackerFileNotifier *notifier,
GFile *file)
TrackerFileNotifierPrivate *priv;
GFile *canonical;
gboolean found;
g_return_val_if_fail (TRACKER_IS_FILE_NOTIFIER (notifier), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
priv = tracker_file_notifier_get_instance_private (notifier);
if (G_UNLIKELY (priv->connection == NULL)) {
return FALSE;
canonical = tracker_file_system_get_file (priv->file_system,
if (!canonical) {
return FALSE;
found = tracker_file_system_get_property_full (priv->file_system,
if (!found) {
TrackerSparqlCursor *cursor;
TrackerSparqlStatement *statement;
gchar *uri;
/* Fetch data for this file synchronously */
statement = sparql_exists_ensure_statement (notifier, NULL);
if (!statement)
return FALSE;
uri = g_file_get_uri (file);
tracker_sparql_statement_bind_string (statement, "file", uri);
g_free (uri);
cursor = tracker_sparql_statement_execute (statement, NULL, NULL);
if (!cursor)
return FALSE;
if (!tracker_sparql_cursor_next (cursor, NULL, NULL)) {
g_object_unref (cursor);
return FALSE;
found = tracker_sparql_cursor_get_boolean (cursor, 0);
g_object_unref (cursor);
return found;
static gboolean
file_notifier_invalidate_file_iri_foreach (GFile *file,
gpointer user_data)
......@@ -92,6 +92,8 @@ const gchar * tracker_file_notifier_get_file_iri (TrackerFileNotifier *notif
void tracker_file_notifier_invalidate_file_iri (TrackerFileNotifier *notifier,
GFile *file,
gboolean recursive);
gboolean tracker_file_notifier_query_file_exists (TrackerFileNotifier *notifier,
GFile *file);
GFileType tracker_file_notifier_get_file_type (TrackerFileNotifier *notifier,
GFile *file);
......@@ -1455,7 +1455,6 @@ item_move (TrackerMinerFS *fs,
gchar *uri, *source_uri, *sparql;
GFileInfo *file_info;
const gchar *source_iri;
gboolean source_exists;
TrackerDirectoryFlags source_flags, flags;
gboolean recursive;
......@@ -1470,9 +1469,8 @@ item_move (TrackerMinerFS *fs,
/* Get 'source' ID */
source_iri = tracker_file_notifier_get_file_iri (fs->priv->file_notifier,
source_file, TRUE);
source_exists = (source_iri != NULL);
source_exists = tracker_file_notifier_query_file_exists (fs->priv->file_notifier,
if (!file_info) {
gboolean retval;
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