[tracker/index-mount-points: 1/4] libtracker-miner: Add tracker_miner_fs_mount_add()
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/index-mount-points: 1/4] libtracker-miner: Add tracker_miner_fs_mount_add()
- Date: Thu, 31 Jan 2013 18:38:54 +0000 (UTC)
commit 4d52ad331b1441256389b117130f8a61955c77cc
Author: Felipe Borges <felipe10borges gmail com>
Date: Fri Aug 10 15:57:13 2012 -0300
libtracker-miner: Add tracker_miner_fs_mount_add()
This function allows adding a mount point to the store, regardless
of the state of the index-removable-devices and index-optical-discs
gsettings options. It is a mechanism to escape the strict duality
dictated by these gsettings keys.
src/libtracker-miner/tracker-miner-fs.c | 117 +++++++++++++++++++++++++++++++
src/libtracker-miner/tracker-miner-fs.h | 2 +
2 files changed, 119 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index e5fec2e..d4de587 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -24,6 +24,7 @@
#include <libtracker-common/tracker-file-utils.h>
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-ontologies.h>
#include "tracker-crawler.h"
#include "tracker-marshal.h"
@@ -36,6 +37,7 @@
#include "tracker-task-pool.h"
#include "tracker-sparql-buffer.h"
#include "tracker-file-notifier.h"
+#include "tracker-storage.h"
/* If defined will print the tree from GNode while running */
#ifdef CRAWLED_TREE_ENABLE_TRACE
@@ -2890,6 +2892,121 @@ tracker_miner_fs_directory_add (TrackerMinerFS *fs,
}
static void
+set_up_mount_point_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source);
+ gchar *device_urn = user_data;
+ GError *error = NULL;
+
+ tracker_sparql_connection_update_finish (connection, result, &error);
+
+ if (error) {
+ g_critical ("Could not set mount point in database '%s', %s",
+ device_urn,
+ error->message);
+ g_critical ("Could not set mount point in database '%s', %s",
+ device_urn,
+ error->message);
+ g_error_free (error);
+ }
+
+ g_free (device_urn);
+}
+
+/**
+ * tracker_miner_fs_mount_add:
+ * @fs: a #TrackerMinerFS
+ * @mount: #GMount for the mount-point to inspect
+ *
+ * Tells the filesystem miner to inspect a mount. It ignores the values
+ * of the index-removable-devices and index-optical-discs gsettings keys.
+ *
+ * Since: 0.14
+ **/
+void
+tracker_miner_fs_mount_add (TrackerMinerFS *fs,
+ GMount *mount)
+{
+ GFile *mount_point;
+ gchar *uri;
+ GString *queries;
+ TrackerStorage *storage;
+ gchar *iri;
+ gchar *uuid;
+ gchar *urn;
+ TrackerStorageType type;
+
+ mount_point = g_mount_get_root (mount);
+ uri = g_file_get_uri (mount_point);
+
+ queries = g_string_new (NULL);
+
+ storage = tracker_storage_new ();
+
+ /* Query the store for the URN of the mount point */
+ iri = tracker_miner_fs_query_urn (TRACKER_MINER_FS (fs), mount_point);
+
+ if (iri) {
+ /* if mount point exists in the store, nothing else to do */
+ g_message ("Mount point '%s' already exists in store: '%s'", uri, iri);
+
+ g_free (iri);
+ } 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);
+ /* 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);
+ }
+
+ 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);
+
+ 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));
+
+ g_string_free (queries, TRUE);
+
+ tracker_miner_fs_directory_add (fs, mount_point, TRUE);
+
+ g_object_unref (mount_point);
+}
+
+static void
task_pool_cancel_foreach (gpointer data,
gpointer user_data)
{
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index f4642a1..428ede9 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -97,6 +97,8 @@ 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]