diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2017-06-17 21:41:10 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2017-06-29 20:49:05 +0200 |
commit | 3e5601ba0b7c91f2436ae2078db9e371062337fc (patch) | |
tree | 73f462716ec330393fd408fd5a4d1270824e3aa4 /src/miners/fs/tracker-miner-files.c | |
parent | 7e3f1f3214f68664c4196dbf11826052ac10ec1e (diff) | |
download | tracker-3e5601ba0b7c91f2436ae2078db9e371062337fc.tar.gz |
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.
Diffstat (limited to 'src/miners/fs/tracker-miner-files.c')
-rw-r--r-- | src/miners/fs/tracker-miner-files.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c index 4bdaf06c1..ecf59bce7 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) |