Commit 805e2e24 authored by Carlos Garnacho's avatar Carlos Garnacho

tracker-miner-fs: Port file processing to TrackerResource

Removes usage of a bunch of deprecated calls.
parent a284a86d
...@@ -2204,18 +2204,15 @@ miner_files_get_file_urn (TrackerMinerFiles *miner, ...@@ -2204,18 +2204,15 @@ miner_files_get_file_urn (TrackerMinerFiles *miner,
} }
static void static void
miner_files_add_to_datasource (TrackerMinerFiles *mf, miner_files_add_to_datasource (TrackerMinerFiles *mf,
GFile *file, GFile *file,
TrackerSparqlBuilder *sparql) TrackerResource *resource)
{ {
TrackerMinerFilesPrivate *priv; TrackerMinerFilesPrivate *priv;
const gchar *removable_device_uuid; const gchar *removable_device_uuid;
gchar *removable_device_urn, *uri; gchar *removable_device_urn;
const gchar *urn;
gboolean is_iri;
priv = TRACKER_MINER_FILES_GET_PRIVATE (mf); priv = TRACKER_MINER_FILES_GET_PRIVATE (mf);
uri = g_file_get_uri (file);
removable_device_uuid = tracker_storage_get_uuid_for_file (priv->storage, file); removable_device_uuid = tracker_storage_get_uuid_for_file (priv->storage, file);
...@@ -2226,31 +2223,17 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf, ...@@ -2226,31 +2223,17 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf,
removable_device_urn = g_strdup (TRACKER_DATASOURCE_URN_NON_REMOVABLE_MEDIA); removable_device_urn = g_strdup (TRACKER_DATASOURCE_URN_NON_REMOVABLE_MEDIA);
} }
urn = miner_files_get_file_urn (mf, file, &is_iri); tracker_resource_set_uri (resource, "nie:dataSource", removable_device_urn);
if (is_iri) {
tracker_sparql_builder_subject_iri (sparql, urn);
} else {
tracker_sparql_builder_subject (sparql, urn);
}
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "nfo:FileDataObject");
tracker_sparql_builder_predicate (sparql, "nie:dataSource");
tracker_sparql_builder_object_iri (sparql, removable_device_urn);
tracker_sparql_builder_predicate (sparql, "tracker:available"); tracker_resource_set_boolean (resource, "tracker:available", TRUE);
tracker_sparql_builder_object_boolean (sparql, TRUE);
g_free (removable_device_urn); g_free (removable_device_urn);
g_free (uri);
} }
static void static void
miner_files_add_rdf_types (TrackerSparqlBuilder *sparql, miner_files_add_rdf_types (TrackerResource *resource,
GFile *file, GFile *file,
const gchar *mime_type) const gchar *mime_type)
{ {
GStrv rdf_types; GStrv rdf_types;
gint i = 0; gint i = 0;
...@@ -2260,13 +2243,9 @@ miner_files_add_rdf_types (TrackerSparqlBuilder *sparql, ...@@ -2260,13 +2243,9 @@ miner_files_add_rdf_types (TrackerSparqlBuilder *sparql,
if (!rdf_types) if (!rdf_types)
return; return;
if (rdf_types[0]) { while (rdf_types[i]) {
tracker_sparql_builder_predicate (sparql, "a"); tracker_resource_add_uri (resource, "rdf:type", rdf_types[i]);
i++;
while (rdf_types[i]) {
tracker_sparql_builder_object (sparql, rdf_types[i]);
i++;
}
} }
g_strfreev (rdf_types); g_strfreev (rdf_types);
...@@ -2289,9 +2268,6 @@ update_mount_point_sparql (ProcessFileData *data) ...@@ -2289,9 +2268,6 @@ update_mount_point_sparql (ProcessFileData *data)
{ {
const gchar *uuid; const gchar *uuid;
tracker_sparql_builder_graph_close (data->sparql);
tracker_sparql_builder_insert_close (data->sparql);
uuid = g_object_get_qdata (G_OBJECT (data->file), uuid = g_object_get_qdata (G_OBJECT (data->file),
data->miner->private->quark_mount_point_uuid); data->miner->private->quark_mount_point_uuid);
...@@ -2338,21 +2314,20 @@ process_file_cb (GObject *object, ...@@ -2338,21 +2314,20 @@ process_file_cb (GObject *object,
gpointer user_data) gpointer user_data)
{ {
TrackerMinerFilesPrivate *priv; TrackerMinerFilesPrivate *priv;
TrackerSparqlBuilder *sparql; TrackerResource *resource;
ProcessFileData *data; ProcessFileData *data;
const gchar *mime_type, *urn, *parent_urn; const gchar *mime_type, *urn, *parent_urn;
gchar *delete_properties_sparql = NULL, *mount_point_sparql; gchar *delete_properties_sparql = NULL, *mount_point_sparql;
GFileInfo *file_info; GFileInfo *file_info;
guint64 time_; guint64 time_;
GFile *file, *parent; GFile *file, *parent;
gchar *uri, *sparql_str; gchar *uri, *sparql_str, *time_str;
GError *error = NULL; GError *error = NULL;
gboolean is_iri; gboolean is_iri;
gboolean is_directory; gboolean is_directory;
data = user_data; data = user_data;
file = G_FILE (object); file = G_FILE (object);
sparql = data->sparql;
file_info = g_file_query_info_finish (file, result, &error); file_info = g_file_query_info_finish (file, result, &error);
priv = TRACKER_MINER_FILES (data->miner)->private; priv = TRACKER_MINER_FILES (data->miner)->private;
...@@ -2400,23 +2375,19 @@ process_file_cb (GObject *object, ...@@ -2400,23 +2375,19 @@ process_file_cb (GObject *object,
urn, urn); urn, urn);
} }
tracker_sparql_builder_insert_silent_open (sparql, NULL); resource = tracker_resource_new (NULL);
tracker_sparql_builder_graph_open (sparql, TRACKER_OWN_GRAPH_URN);
if (is_iri) { if (is_iri) {
tracker_sparql_builder_subject_iri (sparql, urn); tracker_resource_set_identifier (resource, urn);
} else {
tracker_sparql_builder_subject (sparql, urn);
} }
tracker_sparql_builder_predicate (sparql, "a"); tracker_resource_add_uri (resource, "rdf:type", "nfo:FileDataObject");
tracker_sparql_builder_object (sparql, "nfo:FileDataObject"); tracker_resource_add_uri (resource, "rdf:type", "nie:InformationElement");
tracker_sparql_builder_object (sparql, "nie:InformationElement");
is_directory = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY ? is_directory = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY ?
TRUE : FALSE); TRUE : FALSE);
if (is_directory) { if (is_directory) {
tracker_sparql_builder_object (sparql, "nfo:Folder"); tracker_resource_add_uri (resource, "rdf:type", "nfo:Folder");
} }
parent = g_file_get_parent (file); parent = g_file_get_parent (file);
...@@ -2424,49 +2395,46 @@ process_file_cb (GObject *object, ...@@ -2424,49 +2395,46 @@ process_file_cb (GObject *object,
g_object_unref (parent); g_object_unref (parent);
if (parent_urn) { if (parent_urn) {
tracker_sparql_builder_predicate (sparql, "nfo:belongsToContainer"); tracker_resource_set_uri (resource, "nfo:belongsToContainer", parent_urn);
tracker_sparql_builder_object_iri (sparql, parent_urn);
g_free (parent_urn); g_free (parent_urn);
} }
tracker_sparql_builder_predicate (sparql, "nfo:fileName"); tracker_resource_set_string (resource, "nfo:fileName",
tracker_sparql_builder_object_string (sparql, g_file_info_get_display_name (file_info)); g_file_info_get_display_name (file_info));
tracker_resource_set_int64 (resource, "nfo:fileSize",
tracker_sparql_builder_predicate (sparql, "nfo:fileSize"); g_file_info_get_size (file_info));
tracker_sparql_builder_object_int64 (sparql, g_file_info_get_size (file_info));
time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED); time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified"); time_str = tracker_date_to_string (time_);
tracker_sparql_builder_object_date (sparql, (time_t *) &time_); tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
g_free (time_str);
time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS); time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastAccessed"); time_str = tracker_date_to_string (time_);
tracker_sparql_builder_object_date (sparql, (time_t *) &time_); tracker_resource_set_string (resource, "nfo:fileLastAccessed", time_str);
g_free (time_str);
/* Laying the link between the IE and the DO. We use IE = DO */ /* Laying the link between the IE and the DO. We use IE = DO */
tracker_sparql_builder_predicate (sparql, "nie:isStoredAs");
if (is_iri) { if (is_iri) {
tracker_sparql_builder_object_iri (sparql, urn); tracker_resource_add_uri (resource, "nie:isStoredAs", urn);
} else { } else {
tracker_sparql_builder_object (sparql, urn); tracker_resource_add_relation (resource, "nie:isStoredAs", resource);
} }
/* The URL of the DataObject (because IE = DO, this is correct) */ /* The URL of the DataObject (because IE = DO, this is correct) */
tracker_sparql_builder_predicate (sparql, "nie:url"); tracker_resource_set_string (resource, "nie:url", uri);
tracker_sparql_builder_object_string (sparql, uri);
tracker_sparql_builder_predicate (sparql, "nie:mimeType"); tracker_resource_set_string (resource, "nie:mimeType", mime_type);
tracker_sparql_builder_object_string (sparql, mime_type);
miner_files_add_to_datasource (data->miner, file, sparql); miner_files_add_to_datasource (data->miner, file, resource);
if (g_file_info_get_size (file_info) > 0) if (g_file_info_get_size (file_info) > 0)
miner_files_add_rdf_types (sparql, file, mime_type); miner_files_add_rdf_types (resource, file, mime_type);
mount_point_sparql = update_mount_point_sparql (data); mount_point_sparql = update_mount_point_sparql (data);
sparql_str = g_strdup_printf ("%s %s %s", sparql_str = g_strdup_printf ("%s %s %s",
delete_properties_sparql ? delete_properties_sparql : "", delete_properties_sparql ? delete_properties_sparql : "",
tracker_sparql_builder_get_result (sparql), tracker_resource_print_sparql_update (resource, NULL, TRACKER_OWN_GRAPH_URN),
mount_point_sparql ? mount_point_sparql : ""); mount_point_sparql ? mount_point_sparql : "");
g_free (delete_properties_sparql); g_free (delete_properties_sparql);
g_free (mount_point_sparql); g_free (mount_point_sparql);
...@@ -2477,6 +2445,7 @@ process_file_cb (GObject *object, ...@@ -2477,6 +2445,7 @@ process_file_cb (GObject *object,
priv->extraction_queue = g_list_remove (priv->extraction_queue, data); priv->extraction_queue = g_list_remove (priv->extraction_queue, data);
process_file_data_free (data); process_file_data_free (data);
g_object_unref (resource);
g_object_unref (file_info); g_object_unref (file_info);
g_free (sparql_str); g_free (sparql_str);
g_free (uri); g_free (uri);
......
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