[tracker] tracker: Add -f argument to "tracker reset" CLI subcommand
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker: Add -f argument to "tracker reset" CLI subcommand
- Date: Sat, 28 May 2016 22:16:09 +0000 (UTC)
commit ae70af4d4d98f386455ce78e4520cc60d9257200
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 25 01:01:53 2016 +0200
tracker: Add -f argument to "tracker reset" CLI subcommand
It takes a file to be reset, works recursively for directories.
Immediately after reset, a reindex will be requested, so the data
is promptly indexed again.
docs/manpages/tracker-reset.1 | 12 +++--
src/tracker/tracker-reset.c | 93 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 99 insertions(+), 6 deletions(-)
---
diff --git a/docs/manpages/tracker-reset.1 b/docs/manpages/tracker-reset.1
index 89dc621..a039cb6 100644
--- a/docs/manpages/tracker-reset.1
+++ b/docs/manpages/tracker-reset.1
@@ -4,7 +4,7 @@
tracker-reset \- Reset the index and configuration
.SH SYNOPSIS
-\fBtracker reset\fR [\-\-hard | \-\-soft] [\-\-config]
+\fBtracker reset\fR [\-\-hard | \-\-soft] [\-\-config] [\-\-file \fIFILE\fR]
.SH DESCRIPTION
The reset command will change either your configuration or index
@@ -34,10 +34,12 @@ you have a corrupt database but want to reply the journal to restore
it to the last known good place.
.TP
.B \-c, \-\-config
-This removes all config files in \fI$HOME/.config/tracker\fR. All
-files listed are files which were found and successfully removed.
-Restarting the respective processes re-creates the default
-configuration files.
+Resets all configuration to its defaults.
+.TP
+.B \-f, \-\-file \fIFILE\fR
+Resets all indexed information about \fIFILE\fR, works recursively for
+directories. Nothing will be done if \fIFILE\fR is not currently indexed.
+After deletion, a request to reindex this data will be immediately issued.
.SH SEE ALSO
.BR tracker-daemon (1).
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index c92389f..cc2fa87 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -29,6 +29,7 @@
#include <libtracker-common/tracker-common.h>
#include <libtracker-data/tracker-data.h>
+#include <libtracker-control/tracker-control.h>
#include "tracker-reset.h"
#include "tracker-daemon.h"
@@ -39,11 +40,13 @@
static gboolean hard_reset;
static gboolean soft_reset;
static gboolean remove_config;
+static gchar *filename = NULL;
#define RESET_OPTIONS_ENABLED() \
(hard_reset || \
soft_reset || \
- remove_config)
+ remove_config || \
+ filename)
static GOptionEntry entries[] = {
{ "hard", 'r', 0, G_OPTION_ARG_NONE, &hard_reset,
@@ -55,6 +58,10 @@ static GOptionEntry entries[] = {
{ "config", 'c', 0, G_OPTION_ARG_NONE, &remove_config,
N_("Remove all configuration files so they are re-generated on next start"),
NULL },
+ { "file", 'f', 0, G_OPTION_ARG_FILENAME, &filename,
+ N_("Erase indexed information about a file, works recursively for directories"),
+ N_("FILE"),
+ NULL },
{ NULL }
};
@@ -124,6 +131,80 @@ directory_foreach (GFile *file,
g_object_unref (enumerator);
}
+static int
+delete_info_recursively (GFile *file)
+{
+ TrackerSparqlConnection *connection;
+ TrackerMinerManager *miner_manager;
+ TrackerSparqlCursor *cursor;
+ gchar *query, *uri;
+ GError *error = NULL;
+
+ connection = tracker_sparql_connection_get (NULL, &error);
+
+ if (error)
+ goto error;
+
+ uri = g_file_get_uri (file);
+
+ /* First, query whether the item exists */
+ query = g_strdup_printf ("SELECT ?u { ?u nie:url '%s' }", uri);
+ cursor = tracker_sparql_connection_query (connection, query,
+ NULL, &error);
+
+ /* If the item doesn't exist, bail out. */
+ if (!cursor || !tracker_sparql_cursor_next (cursor, NULL, &error)) {
+ g_clear_object (&cursor);
+
+ if (error)
+ goto error;
+
+ return EXIT_SUCCESS;
+ }
+
+ g_object_unref (cursor);
+
+ /* Now, delete the element recursively */
+ g_print ("%s\n", _("Deleting…"));
+ query = g_strdup_printf ("DELETE { "
+ " ?f a rdfs:Resource . "
+ " ?ie a rdfs:Resource "
+ "} WHERE {"
+ " ?f nie:url ?url . "
+ " ?ie nie:isStoredAs ?f . "
+ " FILTER (?url = '%s' ||"
+ " STRSTARTS (?url, '%s/'))"
+ "}", uri, uri);
+ g_free (uri);
+
+ tracker_sparql_connection_update (connection, query,
+ G_PRIORITY_DEFAULT, NULL, &error);
+ g_free (query);
+
+ if (error)
+ goto error;
+
+ g_object_unref (connection);
+
+ g_print ("%s\n", _("The indexed data for this file has been deleted "
+ "and will be reindexed again."));
+
+ /* Request reindexing of this data, it was previously in the store. */
+ miner_manager = tracker_miner_manager_new_full (FALSE, NULL);
+ tracker_miner_manager_index_file (miner_manager, file, &error);
+ g_object_unref (miner_manager);
+
+ if (error)
+ goto error;
+
+ return EXIT_SUCCESS;
+
+error:
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return EXIT_FAILURE;
+}
+
static gint
reset_run (void)
{
@@ -162,6 +243,16 @@ reset_run (void)
}
}
+ if (filename) {
+ GFile *file;
+ gint retval;
+
+ file = g_file_new_for_commandline_arg (filename);
+ retval = delete_info_recursively (file);
+ g_object_unref (file);
+ return retval;
+ }
+
/* KILL processes first... */
if (hard_reset || soft_reset) {
tracker_process_stop (TRACKER_PROCESS_TYPE_NONE, TRACKER_PROCESS_TYPE_ALL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]