[tracker-miners/sam/index-file-sync: 16/18] cli: Remove cruft from `tracker index`



commit e38e9393fc120823dfd6250774ec4d3492f10c9e
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 |  52 ++-----
 src/tracker/tracker-index.c   | 307 +-----------------------------------------
 2 files changed, 15 insertions(+), 344 deletions(-)
---
diff --git a/docs/manpages/tracker-index.1 b/docs/manpages/tracker-index.1
index fb45670da..b8201b7fa 100644
--- a/docs/manpages/tracker-index.1
+++ b/docs/manpages/tracker-index.1
@@ -1,55 +1,23 @@
 .TH tracker-index 1 "September 2014" GNU "User Commands"
 
 .SH NAME
-tracker-index \- List, pause, resume and command data miners indexing content
+tracker-index \- Index content using the Tracker filesystem miner
 
 .SH SYNOPSIS
 .nf
-\fBtracker index\fR \-\-file <\fIfile1\fR> [[\fIfile2\fR] ...]
-\fBtracker index\fR \-\-import <\fIfile1\fR> [[\fIfile2\fR] ...]
-\fBtracker index\fR \-\-backup <\fIfile\fR> | \-\-restore <\fIfile\fR>
+\fBtracker index\fR <\fIpath\fR> [[\fIpath\fR] ...]
 .fi
 
 .SH 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.
-
-.SH OPTIONS
-.TP
-.B \-f, \-\-index\fR=<\fIfile1\fR> [[\fIfile2\fR] ...]
-(Re)index a file matching the \fIfile\fR name(s) supplied.
-.TP
-.B \-b, \-\-backup\fR=<\fIfile\fR>
-Begins backing up the Tracker databases and save it to the \fIfile\fR
-given.
-.TP
-.B \-o, \-\-restore\fR=<\fIfile\fR>
-Begins restoring a previous backup from the \fIfile\fR which points to
-the location of the backup generated by \fB\-\-backup\fR.
-.TP
-.B \i, \-\-import\fR=<\fIfile1\fR> [[\fIfile2\fR] ...]
-Allows data to be imported into the index / database by providing
-files with Turtle content.
-
-Multiple \fIfile\fR arguments can be provided to import data from
-multiple files.
-
-The \fIfile\fR 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.
 
 .SH SEE ALSO
 .BR tracker (1).
-.BR Turtle.
diff --git a/src/tracker/tracker-index.c b/src/tracker/tracker-index.c
index b28299fae..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.Tracker1.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,
-                                                 G_PRIORITY_DEFAULT, 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.Tracker1",
-                                         "/org/freedesktop/Tracker1/Backup",
-                                         "org.freedesktop.Tracker1.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.Tracker1",
-                                         "/org/freedesktop/Tracker1/Backup",
-                                         "org.freedesktop.Tracker1.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]