summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Borges <felipe10borges@gmail.com>2012-08-15 08:15:02 -0300
committerCosimo Cecchi <cosimoc@gnome.org>2015-01-27 12:27:24 +0000
commit15df2139369e6434b5cf18d99c3a077fb86df746 (patch)
tree8be2ea833e94e251a541e5afb094005453b1c4cd
parent149d70c3360eca1a5d64796672ef29705aa1f213 (diff)
downloadtracker-15df2139369e6434b5cf18d99c3a077fb86df746.tar.gz
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
-rw-r--r--src/libtracker-miner/tracker-miner-fs.c64
-rw-r--r--src/miners/fs/tracker-miner-files-index.c117
-rw-r--r--src/miners/fs/tracker-miner-files-index.xml4
3 files changed, 153 insertions, 32 deletions
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index b50ed39ca..7ca0f11ff 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -3241,7 +3241,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;
@@ -3251,7 +3251,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);
@@ -3270,48 +3270,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/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index b507e3239..13f095516 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -35,6 +35,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>";
@@ -53,6 +56,11 @@ typedef struct {
} MimeTypesData;
typedef struct {
+ TrackerMinerFS *miner;
+ GFile *file;
+} IndexFileForProcessData;
+
+typedef struct {
TrackerMinerFiles *files_miner;
GDBusConnection *d_connection;
GDBusNodeInfo *introspection_data;
@@ -377,6 +385,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,
@@ -395,6 +510,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 ();
}
diff --git a/src/miners/fs/tracker-miner-files-index.xml b/src/miners/fs/tracker-miner-files-index.xml
index afe336401..4e02ba3d7 100644
--- a/src/miners/fs/tracker-miner-files-index.xml
+++ b/src/miners/fs/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>