[tracker/wip/carlosg/domain-ontologies: 67/116] libtracker-miner: Split ::remove-file into two signals
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/domain-ontologies: 67/116] libtracker-miner: Split ::remove-file into two signals
- Date: Sun, 25 Jun 2017 13:10:47 +0000 (UTC)
commit 5168196319ef2d92e006cbf12873bb9b0450b66c
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jun 17 21:41:10 2017 +0200
libtracker-miner: Split ::remove-file into two signals
The only_children argument is a bit awkward as we emit ::remove-file
on a file that is not removed at all. The TrackerSparqlBuilder argument
has been also removed (the signals just have a gchar* return value
containing the SPARQL for the delete op) so it's up to the caller to
decide how to compose the SPARQL.
This allows removing some more knowledge about specific ontologies
from TrackerMinerFS, the ontology-dependent upper layers will know
better how to delete the corresponding entities.
src/libtracker-miner/tracker-miner-fs.c | 106 ++++++--------------------
src/libtracker-miner/tracker-miner-fs.h | 8 +-
src/miners/apps/tracker-miner-applications.c | 20 +++++
src/miners/fs/tracker-miner-files.c | 56 ++++++++++++++
4 files changed, 102 insertions(+), 88 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index bd55a59..e7cb021 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -266,6 +266,7 @@ enum {
WRITEBACK_FILE,
FINISHED_ROOT,
REMOVE_FILE,
+ REMOVE_CHILDREN,
LAST_SIGNAL
};
@@ -282,10 +283,6 @@ enum {
static void miner_fs_initable_iface_init (GInitableIface *iface);
-static gboolean miner_fs_remove_file (TrackerMinerFS *fs,
- GFile *file,
- gboolean children_only,
- TrackerSparqlBuilder *builder);
static void fs_finalize (GObject *object);
static void fs_constructed (GObject *object);
static void fs_set_property (GObject *object,
@@ -372,8 +369,6 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
TrackerMinerClass *miner_class = TRACKER_MINER_CLASS (klass);
- klass->remove_file = miner_fs_remove_file;
-
object_class->finalize = fs_finalize;
object_class->constructed = fs_constructed;
object_class->set_property = fs_set_property;
@@ -629,10 +624,17 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (TrackerMinerFSClass, remove_file),
NULL, NULL, NULL,
- G_TYPE_BOOLEAN,
- 3,
- G_TYPE_FILE, G_TYPE_BOOLEAN,
- TRACKER_SPARQL_TYPE_BUILDER);
+ G_TYPE_STRING,
+ 1, G_TYPE_FILE);
+
+ signals[REMOVE_CHILDREN] =
+ g_signal_new ("remove-children",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerMinerFSClass, remove_children),
+ NULL, NULL, NULL,
+ G_TYPE_STRING,
+ 1, G_TYPE_FILE);
g_type_class_add_private (object_class, sizeof (TrackerMinerFSPrivate));
@@ -781,15 +783,6 @@ miner_fs_initable_iface_init (GInitableIface *iface)
iface->init = miner_fs_initable_init;
}
-static gboolean
-miner_fs_remove_file (TrackerMinerFS *fs,
- GFile *file,
- gboolean children_only,
- TrackerSparqlBuilder *builder)
-{
- return FALSE;
-}
-
static void
fs_finalize (GObject *object)
{
@@ -1543,11 +1536,9 @@ item_remove (TrackerMinerFS *fs,
GFile *file,
gboolean only_children)
{
- TrackerSparqlBuilder *builder;
- gboolean delete_handled = FALSE;
- gchar *uri;
+ gchar *uri, *sparql;
TrackerTask *task;
- guint flags = 0;
+ guint signal_num;
uri = g_file_get_uri (file);
@@ -1563,69 +1554,16 @@ item_remove (TrackerMinerFS *fs,
fs->priv->quark_recursive_removal,
GINT_TO_POINTER (TRUE));
- builder = tracker_sparql_builder_new_update ();
- g_signal_emit (fs, signals[REMOVE_FILE], 0,
- file, only_children, builder, &delete_handled);
+ signal_num = only_children ? REMOVE_CHILDREN : REMOVE_FILE;
+ g_signal_emit (fs, signals[signal_num], 0, file, &sparql);
- if (tracker_sparql_builder_get_length (builder) > 0) {
- task = tracker_sparql_task_new_with_sparql (file, builder);
+ if (sparql) {
+ 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);
- }
-
- g_object_unref (builder);
-
- if (!delete_handled) {
- if (!only_children)
- flags = TRACKER_BULK_MATCH_EQUALS;
-
- if (tracker_file_notifier_get_file_type (fs->priv->file_notifier, file) ==
G_FILE_TYPE_DIRECTORY)
- flags |= TRACKER_BULK_MATCH_CHILDREN;
-
- /* FIRST:
- * Remove tracker:available for the resources we're going to remove.
- * This is done so that unavailability of the resources is marked as soon
- * as possible, as the actual delete may take reaaaally a long time
- * (removing resources for 30GB of files takes even 30minutes in a 1-CPU
- * device). */
-
- /* Add new task to processing pool */
- task = tracker_sparql_task_new_bulk (file,
- "DELETE { "
- " ?f tracker:available true "
- "}",
- flags);
-
- tracker_sparql_buffer_push (fs->priv->sparql_buffer,
- task,
- G_PRIORITY_DEFAULT,
- sparql_buffer_task_finished_cb,
- fs);
- tracker_task_unref (task);
-
- /* SECOND:
- * Actually remove all resources. This operation is the one which may take
- * a long time.
- */
-
- /* Add new task to processing pool */
- task = tracker_sparql_task_new_bulk (file,
- "DELETE { "
- " ?f a rdfs:Resource . "
- " ?ie a rdfs:Resource "
- "}",
- flags |
- TRACKER_BULK_MATCH_LOGICAL_RESOURCES);
-
- tracker_sparql_buffer_push (fs->priv->sparql_buffer,
- task,
- G_PRIORITY_DEFAULT,
- sparql_buffer_task_finished_cb,
- fs);
+ task,
+ G_PRIORITY_DEFAULT,
+ sparql_buffer_task_finished_cb,
+ fs);
tracker_task_unref (task);
}
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 953d29a..151f700 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -96,10 +96,10 @@ typedef struct {
gint directories_ignored,
gint files_found,
gint files_ignored);
- gboolean (* remove_file) (TrackerMinerFS *fs,
- GFile *file,
- gboolean children_only,
- TrackerSparqlBuilder *builder);
+ gchar * (* remove_file) (TrackerMinerFS *fs,
+ GFile *file);
+ gchar * (* remove_children) (TrackerMinerFS *fs,
+ GFile *file);
/* <Private> */
gpointer padding[8];
diff --git a/src/miners/apps/tracker-miner-applications.c b/src/miners/apps/tracker-miner-applications.c
index 348c3e0..1133d21 100644
--- a/src/miners/apps/tracker-miner-applications.c
+++ b/src/miners/apps/tracker-miner-applications.c
@@ -42,6 +42,8 @@ static gboolean miner_applications_process_file (TrackerMinerFS
static gboolean miner_applications_process_file_attributes (TrackerMinerFS *fs,
GFile *file,
GTask *task);
+static gchar * miner_applications_remove_file (TrackerMinerFS *fs,
+ GFile *file);
static GQuark miner_applications_error_quark = 0;
@@ -70,6 +72,7 @@ tracker_miner_applications_class_init (TrackerMinerApplicationsClass *klass)
miner_fs_class->process_file = miner_applications_process_file;
miner_fs_class->process_file_attributes = miner_applications_process_file_attributes;
+ miner_fs_class->remove_file = miner_applications_remove_file;
miner_applications_error_quark = g_quark_from_static_string ("TrackerMinerApplications");
}
@@ -935,6 +938,23 @@ miner_applications_process_file_attributes (TrackerMinerFS *fs,
return FALSE;
}
+static gchar *
+miner_applications_remove_file (TrackerMinerFS *fs,
+ GFile *file)
+{
+ gchar *uri, *sparql;
+
+ uri = g_file_get_uri (file);
+ sparql = g_strdup_printf ("DELETE {"
+ " ?u a rdfs:Resource"
+ "} WHERE {"
+ " ?u nie:url \"%s\""
+ "}", uri);
+ g_free (uri);
+
+ return sparql;
+}
+
TrackerMiner *
tracker_miner_applications_new (GError **error)
{
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 4bdaf06..ecf59bc 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -179,6 +179,10 @@ static gboolean miner_files_process_file (TrackerMinerFS *f
static gboolean miner_files_process_file_attributes (TrackerMinerFS *fs,
GFile *file,
GTask *task);
+static gchar * miner_files_remove_children (TrackerMinerFS *fs,
+ GFile *file);
+static gchar * miner_files_remove_file (TrackerMinerFS *fs,
+ GFile *file);
static void miner_files_finished (TrackerMinerFS *fs,
gdouble elapsed,
gint directories_found,
@@ -224,6 +228,8 @@ tracker_miner_files_class_init (TrackerMinerFilesClass *klass)
miner_fs_class->process_file = miner_files_process_file;
miner_fs_class->process_file_attributes = miner_files_process_file_attributes;
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;
g_object_class_install_property (object_class,
PROP_CONFIG,
@@ -2428,6 +2434,56 @@ miner_files_finished (TrackerMinerFS *fs,
tracker_miner_files_set_last_crawl_done (TRUE);
}
+static gchar *
+create_delete_sparql (GFile *file,
+ gboolean delete_self,
+ gboolean delete_children)
+{
+ GString *sparql;
+ gchar *uri;
+
+ g_return_val_if_fail (delete_self || delete_children, NULL);
+
+ uri = g_file_get_uri (file);
+ sparql = g_string_new ("DELETE {"
+ " ?f a rdfs:Resource . "
+ " ?ie a rdfs:Resource "
+ "} WHERE {"
+ " ?f a rdfs:Resource ; "
+ " nie:url ?u . "
+ " ?ie nie:isStoredAs ?f . "
+ " FILTER (");
+
+ if (delete_self)
+ g_string_append_printf (sparql, "?u = \"%s\" ", uri);
+
+ if (delete_children) {
+ if (delete_self)
+ g_string_append (sparql, " || ");
+
+ g_string_append_printf (sparql, "STRSTARTS (?u, \"%s/\")", uri);
+ }
+
+ g_string_append (sparql, ")}");
+ g_free (uri);
+
+ return g_string_free (sparql, FALSE);
+}
+
+static gchar *
+miner_files_remove_children (TrackerMinerFS *fs,
+ GFile *file)
+{
+ return create_delete_sparql (file, FALSE, TRUE);
+}
+
+static gchar *
+miner_files_remove_file (TrackerMinerFS *fs,
+ GFile *file)
+{
+ return create_delete_sparql (file, TRUE, TRUE);
+}
+
TrackerMiner *
tracker_miner_files_new (TrackerConfig *config,
GError **error)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]