[tracker/sam/index-mount-points: 1/11] libtracker-miner: Add tracker_miner_fs_mount_add()



commit bb40f882944745ffea6d14b131db3913650b89b2
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 |  116 +++++++++++++++++++++++++++++++
 src/libtracker-miner/tracker-miner-fs.h |    2 +
 2 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 72bba02..d42be42 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -31,6 +31,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
@@ -3243,6 +3244,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 ae23ff8..a143c4d 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -153,6 +153,8 @@ gboolean              tracker_miner_fs_directory_remove      (TrackerMinerFS  *f
                                                               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_force_mtime_checking  (TrackerMinerFS  *fs,
                                                               GFile           *directory);
 


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