[tracker/index-mount-points: 2/4] tracker-miner-fs: Add 'IndexFileForProcess' DBus method



commit 347cf1fd7066553d64c03198ec6c5c9a8c6fe9c5
Author: Felipe Borges <felipe10borges gmail com>
Date:   Wed Aug 15 08:15:02 2012 -0300

    tracker-miner-fs: Add 'IndexFileForProcess' DBus method
    
    This method indexes a given path and watches the request sender bus
    name. It stops the indexing process when no bus names are associated
    with the given file.
    
    Fixes GB#680834

 data/dbus/tracker-miner-files-index.xml   |    4 +
 src/libtracker-miner/tracker-miner-fs.c   |   64 ++++++++--------
 src/libtracker-miner/tracker-miner-fs.h   |    4 +-
 src/miners/fs/tracker-miner-files-index.c |  117 +++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+), 34 deletions(-)
---
diff --git a/data/dbus/tracker-miner-files-index.xml b/data/dbus/tracker-miner-files-index.xml
index afe3364..4e02ba3 100644
--- a/data/dbus/tracker-miner-files-index.xml
+++ b/data/dbus/tracker-miner-files-index.xml
@@ -10,5 +10,9 @@
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="s" name="file_uri" direction="in" />
     </method>
+    <method name="IndexFileForProcess">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="file_uri" direction="in" />
+    </method>
   </interface>
 </node>
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index d4de587..9d79338 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2927,7 +2927,7 @@ set_up_mount_point_cb (GObject      *source,
  **/
 void
 tracker_miner_fs_mount_add (TrackerMinerFS *fs,
-							GMount		   *mount)
+                            GMount         *mount)
 {
 	GFile *mount_point;
 	gchar *uri;
@@ -2937,7 +2937,7 @@ tracker_miner_fs_mount_add (TrackerMinerFS *fs,
 	gchar *uuid;
 	gchar *urn;
 	TrackerStorageType type;
-	
+
 	mount_point = g_mount_get_root (mount);
 	uri = g_file_get_uri (mount_point);
 
@@ -2956,48 +2956,48 @@ tracker_miner_fs_mount_add (TrackerMinerFS *fs,
 	} else {
 		/* If it doesn't exist, we need to create it */
 		g_message ("Mount point '%s' does not exist in store, need to create it",
-					uri);
+		           uri);
 		/* Create a nfo:Folder for the mount point */
 		g_string_append_printf (queries,
-								"INSERT SILENT INTO <" TRACKER_MINER_FS_GRAPH_URN "> {"
-								" _:file a nfo:FileDataObject, nie:InformationElement, nfo:Folder ; "
-								"        nie:isStoredAs _:file ; "
-								"        nie:url \"%s\" ; "
-								"        nie:mimeType \"inode/directory\" ; "
-								"        nfo:fileLastModified \"1981-06-05T02:20:00Z\" . "
-								"}",
-								uri);
+		                        "INSERT SILENT INTO <" TRACKER_MINER_FS_GRAPH_URN "> {"
+		                        " _:file a nfo:FileDataObject, nie:InformationElement, nfo:Folder ; "
+		                        "        nie:isStoredAs _:file ; "
+		                        "        nie:url \"%s\" ; "
+		                        "        nie:mimeType \"inode/directory\" ; "
+		                        "        nfo:fileLastModified \"1981-06-05T02:20:00Z\" . "
+		                        "}",
+		                        uri);
 	}
 
-	uuid = tracker_storage_get_uuid_for_file (storage, mount_point);	
+	uuid = tracker_storage_get_uuid_for_file (storage, mount_point);
 	urn = g_strconcat (TRACKER_DATASOURCE_URN_PREFIX, uuid, NULL);
 	type = tracker_storage_get_type_for_uuid (storage, uuid);
 	g_free (uuid);
 
 	g_string_append_printf (queries,
-							"DELETE { <%s> a rdfs:Resource }  "
-							"INSERT OR REPLACE { "
-							"  <%s> a tracker:Volume; "
-							"       tracker:mountPoint ?u ; "
-							"		tracker:isRemovable %s ; "
-							"		tracker:isOptical %s"
-							"} WHERE { "
-							"  ?u a nfo:FileDataObject; "
-							"     nie:url \"%s\" "
-							"} ",
-							urn, urn, 
-							TRACKER_STORAGE_TYPE_IS_REMOVABLE (type) ? "true" : "false",
-							TRACKER_STORAGE_TYPE_IS_OPTICAL (type) ? "true" : "false",
-							uri);
-	
+	                        "DELETE { <%s> a rdfs:Resource }  "
+	                        "INSERT OR REPLACE { "
+	                        "  <%s> a tracker:Volume; "
+	                        "       tracker:mountPoint ?u ; "
+	                        "		tracker:isRemovable %s ; "
+	                        "		tracker:isOptical %s"
+	                        "} WHERE { "
+	                        "  ?u a nfo:FileDataObject; "
+	                        "     nie:url \"%s\" "
+	                        "} ",
+	                        urn,
+	                        urn,
+	                        TRACKER_STORAGE_TYPE_IS_REMOVABLE (type) ? "true" : "false",
+	                        TRACKER_STORAGE_TYPE_IS_OPTICAL (type) ? "true" : "false",
+	                        uri);
 	g_free (uri);
 
 	tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
-											queries->str,
-											G_PRIORITY_HIGH,
-											NULL,
-											set_up_mount_point_cb,
-											g_strdup (urn));
+	                                        queries->str,
+	                                        G_PRIORITY_HIGH,
+	                                        NULL,
+	                                        set_up_mount_point_cb,
+	                                        g_strdup (urn));
 
 	g_string_free (queries, TRUE);
 
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 428ede9..6c20abc 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -97,12 +97,12 @@ GType                 tracker_miner_fs_get_type             (void) G_GNUC_CONST;
 void                  tracker_miner_fs_directory_add        (TrackerMinerFS *fs,
                                                              GFile          *file,
                                                              gboolean        recurse);
-void                  tracker_miner_fs_mount_add        (TrackerMinerFS *fs,
-                                                         GMount          *mount);
 gboolean              tracker_miner_fs_directory_remove     (TrackerMinerFS *fs,
                                                              GFile          *file);
 gboolean              tracker_miner_fs_directory_remove_full (TrackerMinerFS *fs,
                                                               GFile          *file);
+void                  tracker_miner_fs_mount_add        (TrackerMinerFS *fs,
+                                                         GMount          *mount);
 void                  tracker_miner_fs_check_file_with_priority (TrackerMinerFS *fs,
                                                                  GFile          *file,
                                                                  gint            priority,
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index 26ae704..f24ca3b 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -36,6 +36,9 @@ static const gchar introspection_xml[] =
   "    <method name='IndexFile'>"
   "      <arg type='s' name='file_uri' direction='in' />"
   "    </method>"
+  "    <method name='IndexFileForProcess'>"
+  "      <arg type='s' name='file_uri' direction='in' />"
+  "    </method>"
   "  </interface>"
   "</node>";
 
@@ -54,6 +57,11 @@ typedef struct {
 } MimeTypesData;
 
 typedef struct {
+	TrackerMinerFS *miner;
+	GFile *file;
+} IndexFileForProcessData;
+
+typedef struct {
 	TrackerMinerFiles *files_miner;
 	GDBusConnection *d_connection;
 	GDBusNodeInfo *introspection_data;
@@ -378,6 +386,113 @@ handle_method_call_index_file (TrackerMinerFilesIndex *miner,
 }
 
 static void
+on_application_appears (GDBusConnection *connection,
+                		const gchar     *name,
+                		const gchar     *name_owner,
+                		gpointer         user_data)
+{
+	IndexFileForProcessData *data = user_data;
+	GFileInfo *file_info;
+	gboolean *is_dir;
+	gboolean *is_mount;
+
+	file_info = g_file_query_info (data->file,
+	                               G_FILE_ATTRIBUTE_STANDARD_TYPE,
+	                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+	                               NULL, NULL);
+
+	is_mount = g_file_find_enclosing_mount (data->file, NULL, NULL) ? TRUE : FALSE;
+	is_dir = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
+
+	g_object_unref (file_info);
+
+	if (is_mount) {
+		tracker_miner_fs_mount_add (TRACKER_MINER_FS (data->miner), g_file_find_enclosing_mount (data->file, NULL, NULL));
+	} else if (is_dir) {
+		tracker_miner_fs_check_directory (TRACKER_MINER_FS (data->miner), data->file, FALSE);
+	} else {
+		tracker_miner_fs_check_file (TRACKER_MINER_FS (data->miner), data->file, FALSE);
+	}
+
+	g_slice_free (IndexFileForProcessData, data);
+
+}
+
+static void
+on_application_disappears (GDBusConnection *connection,
+                           const gchar     *name,
+                           gpointer         user_data)
+{
+	IndexFileForProcessData *data = user_data;
+
+	tracker_miner_fs_directory_remove (TRACKER_MINER_FS (data->miner), data->file);
+}
+
+static void
+handle_method_call_index_file_for_process (TrackerMinerFilesIndex *miner,
+                                		   GDBusMethodInvocation  *invocation,
+                                           GVariant               *parameters)
+{
+	TrackerMinerFilesIndexPrivate *priv;
+	TrackerDBusRequest *request;	
+	GFile *file;
+	GFileInfo *file_info;
+	const gchar *sender;
+	GError *internal_error;
+	IndexFileForProcessData *data;
+	const gchar *file_uri;
+
+	priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (miner);
+
+	g_variant_get (parameters, "(&s)", &file_uri);
+
+	tracker_gdbus_async_return_if_fail (file_uri != NULL, invocation);
+
+	request = tracker_g_dbus_request_begin (invocation, "%s(uri:'%s')", __FUNCTION__, file_uri);
+
+	file = g_file_new_for_uri (file_uri);
+
+
+
+	file_info = g_file_query_info (file,
+	                               G_FILE_ATTRIBUTE_STANDARD_TYPE,
+	                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+	                               NULL, NULL);
+
+	if (!file_info) {
+		internal_error = g_error_new_literal (1, 0, "File does not exist");
+		tracker_dbus_request_end (request, internal_error);
+		g_dbus_method_invocation_return_gerror (invocation, internal_error);
+
+		g_error_free (internal_error);
+
+		g_object_unref (file);
+
+		return;
+	}
+
+	g_object_unref (file_info);
+
+	data = g_slice_new (IndexFileForProcessData);
+	data->miner = g_object_ref (TRACKER_MINER_FS (priv->files_miner));
+	data->file = g_object_ref (file);
+
+	g_object_unref (file);
+
+	sender = g_dbus_method_invocation_get_sender (invocation);
+	g_bus_watch_name (G_BUS_TYPE_SESSION,
+                      sender,
+                      G_BUS_NAME_WATCHER_FLAGS_NONE,
+                      on_application_appears,
+                      on_application_disappears,
+                      data,
+                      NULL);
+
+	tracker_dbus_request_end (request, NULL);
+	g_dbus_method_invocation_return_value (invocation, NULL);
+}
+
+static void
 handle_method_call (GDBusConnection       *connection,
                     const gchar           *sender,
                     const gchar           *object_path,
@@ -396,6 +511,8 @@ handle_method_call (GDBusConnection       *connection,
 		tracker_miner_files_index_reindex_mime_types (miner, invocation, parameters);
 	} else if (g_strcmp0 (method_name, "IndexFile") == 0) {
 		handle_method_call_index_file (miner, invocation, parameters);
+	} else if (g_strcmp0 (method_name, "IndexFileForProcess") == 0) {
+		handle_method_call_index_file_for_process (miner, invocation, parameters);
 	} else {
 		g_assert_not_reached ();
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]