[tracker-miners/sam/index-location: 2/21] cli: Remove cruft from `tracker index`
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/index-location: 2/21] cli: Remove cruft from `tracker index`
- Date: Thu, 9 Jul 2020 23:03:55 +0000 (UTC)
commit c76d7dfd4d1b9191bf2017aa67be0dce7f2e8654
Author: Sam Thursfield <sam afuera me uk>
Date: Sun Mar 8 16:41:16 2020 +0100
cli: Remove cruft from `tracker index`
The new `tracker import` and `tracker export` commands have taken on
all the extraneous functionality that `tracker index` had.
docs/manpages/tracker-index.1.txt | 49 ++----
src/tracker/tracker-index.c | 307 +-------------------------------------
2 files changed, 15 insertions(+), 341 deletions(-)
---
diff --git a/docs/manpages/tracker-index.1.txt b/docs/manpages/tracker-index.1.txt
index c2121242e..d1df8cf0a 100644
--- a/docs/manpages/tracker-index.1.txt
+++ b/docs/manpages/tracker-index.1.txt
@@ -3,54 +3,25 @@ tracker-index(1)
== NAME
-tracker-index - List, pause, resume and command data miners indexing
-content
+tracker-index - Index content using the Tracker filesystem miner
== SYNOPSIS
....
-tracker index --file <file1> [[file2] ...]
-tracker index --import <file1> [[file2] ...]
-tracker index --backup <file> | --restore <file>
+tracker index <path> [[path] ...]
....
== DESCRIPTION
-This command perform actions on the current index. The "index" holds a
-snapshot of the working tree in a database.
+This command causes the Tracker filesystem miner to process the given
+files or directories.
-The index command allows some level of control on existing data indexed,
-such as re-indexing content from a specific demographic - e.g. all JPEG
-images, or simply reindexing an existing or non-existent file.
-
-It may be a good idea to backup your index before an upgrade in case
-there is data loss (which should never happen). In those cases, the
-backup command is made available and of course the restore command will
-import an older data set (or index) into an empty index.
-
-Finally, there is an import feature which makes testing or applying a
-"base" data set for use much easier.
-
-== OPTIONS
-
-*-f, --index=<__file1__> [[_file2_] ...]*::
- (Re)index a file matching the _file_ name(s) supplied.
-*-b, --backup=<__file__>*::
- Begins backing up the Tracker databases and save it to the _file_
- given.
-*-o, --restore=<__file__>*::
- Begins restoring a previous backup from the _file_ which points to the
- location of the backup generated by *--backup*.
-*i, --import=<__file1__> [[_file2_] ...]*::
- Allows data to be imported into the index / database by providing
- files with Turtle content.
-
-Multiple _file_ arguments can be provided to import data from multiple
-files.
-
-The _file_ argument can be either a local path or a URI. It also does
-not have to be an absolute path.
+Usually you should configure the miner to automatically index your
+content, because it will monitor the content locations for changes and
+ensure that the index is kept up to date. Content that is added using
+`tracker index` will not be monitored for changes by default, so you can
+end up with stale data in your search results if you use this command.
== SEE ALSO
-*tracker*(1). *Turtle.*
+*tracker-miner-fs*(1).
diff --git a/src/tracker/tracker-index.c b/src/tracker/tracker-index.c
index b8b3d2f1f..fc28deefd 100644
--- a/src/tracker/tracker-index.c
+++ b/src/tracker/tracker-index.c
@@ -36,75 +36,15 @@
#include "tracker-dbus.h"
#include "tracker-miner-manager.h"
-static gboolean index_file;
-static gboolean backup;
-static gboolean restore;
-static gboolean import;
static gchar **filenames;
-#define INDEX_OPTIONS_ENABLED() \
- ((filenames && g_strv_length (filenames) > 0) || \
- (index_file || \
- backup || \
- restore || \
- import))
-
static GOptionEntry entries[] = {
- { "file", 'f', 0, G_OPTION_ARG_NONE, &index_file,
- N_("Tell miners to (re)index a given file"),
- N_("FILE") },
- { "backup", 'b', 0, G_OPTION_ARG_NONE, &backup,
- N_("Backup current index / database to the file provided"),
- NULL },
- { "restore", 'o', 0, G_OPTION_ARG_NONE, &restore,
- N_("Restore a database from a previous backup (see --backup)"),
- NULL },
- { "import", 'i', 0, G_OPTION_ARG_NONE, &import,
- N_("Import a dataset from the provided file (in Turtle format)"),
- NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
N_("FILE"),
N_("FILE") },
{ NULL }
};
-static gboolean
-has_valid_uri_scheme (const gchar *uri)
-{
- const gchar *s;
-
- s = uri;
-
- if (!g_ascii_isalpha (*s)) {
- return FALSE;
- }
-
- do {
- s++;
- } while (g_ascii_isalnum (*s) || *s == '+' || *s == '.' || *s == '-');
-
- return (*s == ':');
-}
-
-static gchar *
-get_uri_from_arg (const gchar *arg)
-{
- gchar *uri;
-
- /* support both, URIs and local file paths */
- if (has_valid_uri_scheme (arg)) {
- uri = g_strdup (arg);
- } else {
- GFile *file;
-
- file = g_file_new_for_commandline_arg (arg);
- uri = g_file_get_uri (file);
- g_object_unref (file);
- }
-
- return uri;
-}
-
static gint
index_or_reindex_file (void)
{
@@ -145,222 +85,10 @@ index_or_reindex_file (void)
return EXIT_SUCCESS;
}
-static int
-import_turtle_files (void)
-{
- TrackerSparqlConnection *connection;
- GError *error = NULL;
- gchar **p;
-
- connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.Files",
- NULL, NULL, &error);
-
- if (!connection) {
- g_printerr ("%s: %s\n",
- _("Could not establish a connection to Tracker"),
- error ? error->message : _("No error given"));
- g_clear_error (&error);
- return EXIT_FAILURE;
- }
-
- for (p = filenames; *p; p++) {
- GError *error = NULL;
- GFile *file;
- gchar *query, *uri;
-
- g_print ("%s:'%s'\n",
- _("Importing Turtle file"),
- *p);
-
- file = g_file_new_for_commandline_arg (*p);
- uri = g_file_get_uri (file);
- query = g_strdup_printf ("LOAD <%s>", uri);
- tracker_sparql_connection_update (connection, query,
- NULL,
- &error);
- g_free (query);
- g_free (uri);
- g_object_unref (file);
-
- if (error) {
- g_printerr (" %s, %s\n",
- _("Unable to import Turtle file"),
- error->message);
-
- g_error_free (error);
- continue;
- }
-
- g_print (" %s\n", _("Done"));
- g_print ("\n");
- }
-
- g_object_unref (connection);
-
- return EXIT_SUCCESS;
-}
-
-static int
-backup_index (void)
-{
- GDBusConnection *connection;
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *v;
- gchar *uri;
-
- if (!tracker_dbus_get_connection ("org.freedesktop.Tracker3",
- "/org/freedesktop/Tracker3/Backup",
- "org.freedesktop.Tracker3.Backup",
- G_DBUS_PROXY_FLAGS_NONE,
- &connection,
- &proxy)) {
- return EXIT_FAILURE;
- }
-
- uri = get_uri_from_arg (filenames[0]);
-
- g_print ("%s\n", _("Backing up database"));
- g_print (" %s\n", uri);
-
- /* Backup/Restore can take some time */
- g_dbus_proxy_set_default_timeout (proxy, G_MAXINT);
-
- v = g_dbus_proxy_call_sync (proxy,
- "Save",
- g_variant_new ("(s)", uri),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (proxy) {
- g_object_unref (proxy);
- }
-
- if (error) {
- g_critical ("%s, %s",
- _("Could not backup database"),
- error ? error->message : _("No error given"));
- g_clear_error (&error);
- g_free (uri);
-
- return EXIT_FAILURE;
- }
-
- if (v) {
- g_variant_unref (v);
- }
-
- g_free (uri);
-
- return EXIT_SUCCESS;
-}
-
-static int
-restore_index (void)
-{
- GDBusConnection *connection;
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *v;
- gchar *uri;
-
- if (!tracker_dbus_get_connection ("org.freedesktop.Tracker3",
- "/org/freedesktop/Tracker3/Backup",
- "org.freedesktop.Tracker3.Backup",
- G_DBUS_PROXY_FLAGS_NONE,
- &connection,
- &proxy)) {
- return EXIT_FAILURE;
- }
-
- uri = get_uri_from_arg (filenames[0]);
-
- g_print ("%s\n", _("Restoring database from backup"));
- g_print (" %s\n", uri);
-
- /* Backup/Restore can take some time */
- g_dbus_proxy_set_default_timeout (proxy, G_MAXINT);
-
- v = g_dbus_proxy_call_sync (proxy,
- "Restore",
- g_variant_new ("(s)", uri),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (proxy) {
- g_object_unref (proxy);
- }
-
- if (error) {
- g_critical ("%s, %s",
- _("Could not backup database"),
- error ? error->message : _("No error given"));
- g_clear_error (&error);
- g_free (uri);
-
- return EXIT_FAILURE;
- }
-
- if (v) {
- g_variant_unref (v);
- }
-
- g_free (uri);
-
- return EXIT_SUCCESS;
-}
-
static int
index_run (void)
{
- if (index_file) {
- return index_or_reindex_file ();
- }
-
- if (import) {
- return import_turtle_files ();
- }
-
- if (backup) {
- return backup_index ();
- }
-
- if (restore) {
- return restore_index ();
- }
-
- /* All known options have their own exit points */
- g_printerr("Use `tracker index --file` when giving a specific file or "
- "directory to index. See `tracker help index` for more "
- "information.\n");
-
- return EXIT_FAILURE;
-}
-
-static int
-index_run_default (void)
-{
- GOptionContext *context;
- gchar *help;
-
- context = g_option_context_new (NULL);
- g_option_context_add_main_entries (context, entries, NULL);
- help = g_option_context_get_help (context, TRUE, NULL);
- g_option_context_free (context);
- g_printerr ("%s\n", help);
- g_free (help);
-
- return EXIT_FAILURE;
-}
-
-static gboolean
-index_options_enabled (void)
-{
- return INDEX_OPTIONS_ENABLED ();
+ return index_or_reindex_file ();
}
int
@@ -369,7 +97,6 @@ main (int argc, const char **argv)
GOptionContext *context;
GError *error = NULL;
const gchar *failed;
- gint actions = 0;
setlocale (LC_ALL, "");
@@ -391,40 +118,16 @@ main (int argc, const char **argv)
g_option_context_free (context);
- if (backup) {
- actions++;
- }
-
- if (restore) {
- actions++;
- }
-
- if (index_file) {
- actions++;
- }
-
- if (import) {
- actions++;
- }
-
- if (actions > 1) {
- failed = _("Only one action (--backup, --restore, --index-file or --import) can be used at a
time");
- } else if (actions > 0 && (!filenames || g_strv_length (filenames) < 1)) {
- failed = _("Missing one or more files which are required");
- } else if ((backup || restore) && (filenames && g_strv_length (filenames) > 1)) {
- failed = _("Only one file can be used with --backup and --restore");
+ if (!filenames || g_strv_length (filenames) < 1) {
+ failed = _("Please specify one or more locations to index.");
} else {
failed = NULL;
}
if (failed) {
- g_printerr ("%s\n\n", failed);
+ g_printerr ("%s\n", failed);
return EXIT_FAILURE;
}
- if (index_options_enabled ()) {
- return index_run ();
- }
-
- return index_run_default ();
+ return index_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]