[tracker/wip/carlosg/domain-ontologies: 73/124] libtracker-miner: Add TrackerMinerFS::move-file vmethod
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/domain-ontologies: 73/124] libtracker-miner: Add TrackerMinerFS::move-file vmethod
- Date: Thu, 29 Jun 2017 18:45:15 +0000 (UTC)
commit 36081cd7a432348db59aedffbff8c5b956b1e027
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jun 17 23:43:22 2017 +0200
libtracker-miner: Add TrackerMinerFS::move-file vmethod
We delegate the SPARQL generation to this vmethod, in order to
keep TrackerMinerFS as agnostic of the ontology as possible.
src/libtracker-miner/tracker-miner-fs.c | 185 +++++++++---------------------
src/libtracker-miner/tracker-miner-fs.h | 4 +
src/miners/fs/tracker-miner-files.c | 85 ++++++++++++++
3 files changed, 145 insertions(+), 129 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index e7cb021..a57fc33 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -267,6 +267,7 @@ enum {
FINISHED_ROOT,
REMOVE_FILE,
REMOVE_CHILDREN,
+ MOVE_FILE,
LAST_SIGNAL
};
@@ -1614,16 +1615,13 @@ item_move (TrackerMinerFS *fs,
GFile *file,
GFile *source_file)
{
- gchar *uri, *source_uri;
+ gchar *uri, *source_uri, *sparql;
GFileInfo *file_info;
- GString *sparql;
TrackerTask *task;
const gchar *source_iri;
- gchar *display_name;
gboolean source_exists;
- GFile *new_parent;
- const gchar *new_parent_iri;
TrackerDirectoryFlags source_flags, flags;
+ gboolean recursive;
uri = g_file_get_uri (file);
source_uri = g_file_get_uri (source_file);
@@ -1678,142 +1676,71 @@ item_move (TrackerMinerFS *fs,
source_uri,
uri);
- if (fs->priv->thumbnailer)
+ tracker_indexing_tree_get_root (fs->priv->indexing_tree, source_file, &source_flags);
+ tracker_indexing_tree_get_root (fs->priv->indexing_tree, file, &flags);
+ recursive = ((source_flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0 &&
+ (flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0 &&
+ g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
+
+ if (fs->priv->thumbnailer) {
tracker_thumbnailer_move_add (fs->priv->thumbnailer, source_uri,
g_file_info_get_content_type (file_info),
uri);
- sparql = g_string_new ("");
+ if (recursive) {
+ ThumbnailMoveData move_data;
+ gchar *query;
+
+ g_debug ("Moving thumbnails within '%s'", uri);
+
+ /* Push all moved files to thumbnailer */
+ move_data.main_loop = g_main_loop_new (NULL, FALSE);
+ move_data.miner = TRACKER_MINER (fs);
+
+ query = g_strdup_printf ("SELECT ?url ?new_url nie:mimeType(?u) {"
+ " ?u a rdfs:Resource ;"
+ " nie:url ?url ."
+ " BIND (CONCAT (\"%s/\", SUBSTR (?url, STRLEN (\"%s/\") +
1)) AS ?new_url) ."
+ " FILTER (STRSTARTS (?url, \"%s/\"))"
+ "}",
+ uri, source_uri, source_uri);
+
+ tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER
(fs)),
+ query,
+ NULL,
+ move_thumbnails_cb,
+ &move_data);
+
+ g_main_loop_run (move_data.main_loop);
+ g_main_loop_unref (move_data.main_loop);
+ g_free (query);
+ }
+ }
+
/* Delete destination item from store if any */
- g_string_append_printf (sparql,
- "DELETE { "
- " ?urn a rdfs:Resource "
- "} WHERE {"
- " ?urn nie:url \"%s\" "
- "}",
- uri);
-
- g_string_append_printf (sparql,
- "DELETE { "
- " <%s> nfo:fileName ?f ; "
- " nie:url ?u ; "
- " nie:isStoredAs ?s ; "
- " nfo:belongsToContainer ?b"
- "} WHERE { "
- " <%s> nfo:fileName ?f ; "
- " nie:url ?u ; "
- " nie:isStoredAs ?s . "
- " OPTIONAL { <%s> nfo:belongsToContainer ?b }"
- "} ",
- source_iri, source_iri, source_iri);
-
- display_name = tracker_sparql_escape_string (g_file_info_get_display_name (file_info));
-
- /* Get new parent information */
- new_parent = g_file_get_parent (file);
- new_parent_iri = lookup_file_urn (fs, new_parent, TRUE);
-
- if (new_parent && new_parent_iri) {
- g_string_append_printf (sparql,
- "INSERT INTO <%s> {"
- " <%s> nfo:fileName \"%s\" ; "
- " nie:url \"%s\" ; "
- " nie:isStoredAs <%s> ; "
- " nfo:belongsToContainer \"%s\""
- "}" ,
- TRACKER_OWN_GRAPH_URN, source_iri,
- display_name, uri,
- source_iri,
- new_parent_iri);
- } else {
- g_warning ("Adding moved item '%s' without nfo:belongsToContainer (new_parent: %p)",
- uri, new_parent);
- g_string_append_printf (sparql,
- "INSERT INTO <%s> {"
- " <%s> nfo:fileName \"%s\" ; "
- " nie:url \"%s\" ; "
- " nie:isStoredAs <%s>"
- "} ",
- TRACKER_OWN_GRAPH_URN, source_iri,
- display_name, uri,
- source_iri);
- }
-
- if (new_parent)
- g_object_unref (new_parent);
- g_free (display_name);
-
- tracker_indexing_tree_get_root (fs->priv->indexing_tree, source_file, &source_flags);
+ item_remove (fs, file, FALSE);
- if ((source_flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0 &&
- g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
- tracker_indexing_tree_get_root (fs->priv->indexing_tree,
- file, &flags);
+ /* If the original location is recursive, but the destination location
+ * is not, remove all children.
+ */
+ if (!recursive &&
+ (source_flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0)
+ item_remove (fs, source_file, TRUE);
- if ((flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0) {
- if (fs->priv->thumbnailer) {
- ThumbnailMoveData move_data;
- gchar *query;
-
- g_debug ("Moving thumbnails within '%s'", uri);
-
- /* Push all moved files to thumbnailer */
- move_data.main_loop = g_main_loop_new (NULL, FALSE);
- move_data.miner = TRACKER_MINER (fs);
-
- query = g_strdup_printf ("SELECT ?url ?new_url nie:mimeType(?u) {"
- " ?u a rdfs:Resource ;"
- " nie:url ?url ."
- " BIND (CONCAT (\"%s/\", SUBSTR (?url, STRLEN
(\"%s/\") + 1)) AS ?new_url) ."
- " FILTER (STRSTARTS (?url, \"%s/\"))"
- "}",
- uri, source_uri, source_uri);
-
- tracker_sparql_connection_query_async (tracker_miner_get_connection
(TRACKER_MINER (fs)),
- query,
- NULL,
- move_thumbnails_cb,
- &move_data);
-
- g_main_loop_run (move_data.main_loop);
- g_main_loop_unref (move_data.main_loop);
- g_free (query);
- }
+ g_signal_emit (fs, signals[MOVE_FILE], 0, file, source_file, recursive, &sparql);
- g_string_append_printf (sparql,
- " DELETE {"
- " ?u nie:url ?url "
- "} INSERT { "
- " GRAPH <" TRACKER_OWN_GRAPH_URN "> {"
- " ?u nie:url ?new_url "
- " }"
- "} WHERE {"
- " ?u a rdfs:Resource;"
- " nie:url ?url ."
- " BIND (CONCAT (\"%s/\", SUBSTR (?url, STRLEN (\"%s/\") +
1)) AS ?new_url) ."
- " FILTER (STRSTARTS (?url, \"%s/\"))"
- "} ",
- uri, source_uri, source_uri);
- } else {
- /* A directory is being moved from a recursive location to
- * a non-recursive one, mark all children as deleted.
- */
- item_remove (fs, source_file, TRUE);
- }
+ if (sparql) {
+ /* Add new task to processing pool */
+ task = tracker_sparql_task_new_take_sparql_str (file, sparql);
+ tracker_sparql_buffer_push (fs->priv->sparql_buffer,
+ task,
+ G_PRIORITY_DEFAULT,
+ sparql_buffer_task_finished_cb,
+ fs);
+ tracker_task_unref (task);
}
- /* Add new task to processing pool */
- task = tracker_sparql_task_new_take_sparql_str (file,
- g_string_free (sparql,
- FALSE));
- tracker_sparql_buffer_push (fs->priv->sparql_buffer,
- task,
- G_PRIORITY_DEFAULT,
- sparql_buffer_task_finished_cb,
- fs);
- tracker_task_unref (task);
-
if (!tracker_task_pool_limit_reached (TRACKER_TASK_POOL (fs->priv->sparql_buffer))) {
item_queue_handlers_set_up (fs);
}
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 151f700..608de92 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -100,6 +100,10 @@ typedef struct {
GFile *file);
gchar * (* remove_children) (TrackerMinerFS *fs,
GFile *file);
+ gchar * (* move_file) (TrackerMinerFS *fs,
+ GFile *source,
+ GFile *dest,
+ gboolean recursive);
/* <Private> */
gpointer padding[8];
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index ecf59bc..e3653de 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -183,6 +183,10 @@ static gchar * miner_files_remove_children (TrackerMinerFS *f
GFile *file);
static gchar * miner_files_remove_file (TrackerMinerFS *fs,
GFile *file);
+static gchar * miner_files_move_file (TrackerMinerFS *fs,
+ GFile *file,
+ GFile *source_file,
+ gboolean recursive);
static void miner_files_finished (TrackerMinerFS *fs,
gdouble elapsed,
gint directories_found,
@@ -230,6 +234,7 @@ tracker_miner_files_class_init (TrackerMinerFilesClass *klass)
miner_fs_class->finished = miner_files_finished;
miner_fs_class->remove_file = miner_files_remove_file;
miner_fs_class->remove_children = miner_files_remove_children;
+ miner_fs_class->move_file = miner_files_move_file;
g_object_class_install_property (object_class,
PROP_CONFIG,
@@ -2484,6 +2489,86 @@ miner_files_remove_file (TrackerMinerFS *fs,
return create_delete_sparql (file, TRUE, TRUE);
}
+static gchar *
+miner_files_move_file (TrackerMinerFS *fs,
+ GFile *file,
+ GFile *source_file,
+ gboolean recursive)
+{
+ GString *sparql = g_string_new (NULL);
+ const gchar *new_parent_iri;
+ gchar *uri, *source_uri, *display_name;
+ gchar *source_iri;
+ gchar *path, *basename;
+ GFile *new_parent;
+
+ uri = g_file_get_uri (file);
+ source_uri = g_file_get_uri (source_file);
+ source_iri = tracker_miner_fs_query_urn (fs, file);
+
+ path = g_file_get_path (file);
+ basename = g_filename_display_basename (path);
+ display_name = tracker_sparql_escape_string (basename);
+ g_free (basename);
+ g_free (path);
+
+ g_string_append_printf (sparql,
+ "DELETE { "
+ " <%s> nfo:fileName ?f ; "
+ " nie:url ?u ; "
+ " nie:isStoredAs ?s ; "
+ " nfo:belongsToContainer ?b"
+ "} WHERE { "
+ " <%s> nfo:fileName ?f ; "
+ " nie:url ?u ; "
+ " nie:isStoredAs ?s . "
+ " OPTIONAL { <%s> nfo:belongsToContainer ?b }"
+ "} ",
+ source_iri, source_iri, source_iri);
+
+ /* Get new parent information */
+ new_parent = g_file_get_parent (file);
+ new_parent_iri = tracker_miner_fs_query_urn (fs, new_parent);
+
+ g_string_append_printf (sparql,
+ "INSERT INTO <" TRACKER_OWN_GRAPH_URN "> {"
+ " <%s> nfo:fileName \"%s\" ; "
+ " nie:url \"%s\" ; "
+ " nie:isStoredAs <%s> ",
+ source_iri, display_name, uri, source_iri);
+
+ if (new_parent && new_parent_iri) {
+ g_string_append_printf (sparql, "; nfo:belongsToContainer \"%s\"",
+ new_parent_iri);
+ }
+
+ g_string_append (sparql, "}");
+
+ if (recursive) {
+ g_string_append_printf (sparql,
+ " DELETE {"
+ " ?u nie:url ?url "
+ "} INSERT { "
+ " GRAPH <" TRACKER_OWN_GRAPH_URN "> {"
+ " ?u nie:url ?new_url "
+ " }"
+ "} WHERE {"
+ " ?u a rdfs:Resource;"
+ " nie:url ?url ."
+ " BIND (CONCAT (\"%s/\", SUBSTR (?url, STRLEN (\"%s/\") + 1)) AS
?new_url) ."
+ " FILTER (STRSTARTS (?url, \"%s/\"))"
+ "} ",
+ uri, source_uri, source_uri);
+ }
+
+ g_free (uri);
+ g_free (source_uri);
+ g_free (display_name);
+ g_clear_object (&new_parent);
+
+ return g_string_free (sparql, FALSE);
+}
+
TrackerMiner *
tracker_miner_files_new (TrackerConfig *config,
GError **error)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]