diff options
author | Martyn Russell <martyn@lanedo.com> | 2014-10-28 16:29:44 +0000 |
---|---|---|
committer | Martyn Russell <martyn@lanedo.com> | 2014-12-10 15:51:35 +0000 |
commit | 8791bfe96c1d00c09fcf57646b1f7aa6d2b18c14 (patch) | |
tree | 08557419e73166e865c7939fbaec637bded9de5a /src/tracker | |
parent | a1d852d08c41e7f2f96b5b82aeb9f6f566031184 (diff) | |
download | tracker-8791bfe96c1d00c09fcf57646b1f7aa6d2b18c14.tar.gz |
tracker: Make sure old commands still work with the new system
Diffstat (limited to 'src/tracker')
-rw-r--r-- | src/tracker/Makefile.am | 11 | ||||
-rwxr-xr-x | src/tracker/tracker-compat | 8 | ||||
-rw-r--r-- | src/tracker/tracker-compatible.c | 235 | ||||
-rw-r--r-- | src/tracker/tracker-compatible.h | 26 | ||||
-rw-r--r-- | src/tracker/tracker-main.c | 24 |
5 files changed, 302 insertions, 2 deletions
diff --git a/src/tracker/Makefile.am b/src/tracker/Makefile.am index fff4bb138..2a8129421 100644 --- a/src/tracker/Makefile.am +++ b/src/tracker/Makefile.am @@ -18,6 +18,8 @@ bin_PROGRAMS = tracker tracker_SOURCES = \ tracker-main.c \ + tracker-compatible.c \ + tracker-compatible.h \ tracker-config.c \ tracker-config.h \ tracker-color.h \ @@ -55,6 +57,15 @@ tracker_LDADD = \ $(BUILD_LIBS) \ $(TRACKER_LIBS) +install-data-hook: tracker-compat + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-control" + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-import" + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-info" + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-search" + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-sparql" + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-stats" + $(AM_V_GEN) cp -f ./$^ "$(DESTDIR)${bindir}/tracker-tag" + # Bash completion completiondir = $(sysconfdir)/bash_completion.d completion_DATA = tracker-prompt.sh diff --git a/src/tracker/tracker-compat b/src/tracker/tracker-compat new file mode 100755 index 000000000..4667ad69b --- /dev/null +++ b/src/tracker/tracker-compat @@ -0,0 +1,8 @@ +#!/bin/sh + +#export TRACKER_OLD_CMD=`echo $0 | sed 's/^[./]*//'` +export TRACKER_OLD_CMD=`basename $0` +echo "WARNING: The '$TRACKER_OLD_CMD' command is no longer available." > /dev/stderr +echo "WARNING: Use 'tracker <command> [<args>]' instead...\n" > /dev/stderr + +./tracker $@ diff --git a/src/tracker/tracker-compatible.c b/src/tracker/tracker-compatible.c new file mode 100644 index 000000000..d9e9db3c6 --- /dev/null +++ b/src/tracker/tracker-compatible.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2014, Lanedo <martyn@lanedo.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "config.h" + +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdlib.h> +#include <unistd.h> + +#include <glib.h> +#include <glib/gi18n.h> + +#include "tracker-compatible.h" + +#warning "This help module 'tracker-compatible' is here for migration only, please remove by 1.6.0" + +static void +prepend_args (const char *prepend_args, + int n_prepend_args, + int at_index, + int argc, + const char **argv, + int *new_argc, + char ***new_argv) +{ + gchar *new_cmd, *old_args; + + old_args = g_strjoinv (" ", (char**) argv + at_index); + new_cmd = g_strdup_printf ("%s %s", prepend_args, old_args); + g_free (old_args); + + *new_argv = g_strsplit (new_cmd, " ", -1); + *new_argc = argc + n_prepend_args; + g_free (new_cmd); +} + +static gboolean +find_arg (const char *arg_long, + const char *arg_short, + int argc, + const char **argv) +{ + const char *p; + int i, arg_long_len, arg_short_len; + + if (argc < 1) { + return FALSE; + } + + arg_long_len = arg_long ? strlen (arg_long) : 0; + arg_short_len = arg_short ? strlen (arg_short) : 0; + + for (i = 0, p = argv[0]; i < argc; p = argv[++i]) { + if (arg_long_len > 0 && strncmp (arg_long, p, arg_long_len) == 0) { + return TRUE; + } else if (arg_short_len > 0 && strncmp (arg_short, p, arg_short_len) == 0) { + return TRUE; + } + } + + return FALSE; +} + +gboolean +tracker_compatible_commands (int argc, + const char **argv, + int *new_argc, + char ***new_argv) +{ + const gchar *old_cmd; + gchar *new_cmd, *old_args; + + /* Get symlink name */ + old_cmd = g_getenv ("TRACKER_OLD_CMD"); + + if (!old_cmd) { + return FALSE; + } + + if (strcmp (old_cmd, "tracker") == 0 || + strncmp (old_cmd, "tracker-", 8) != 0) { + return FALSE; + } + + old_cmd += 8; + + if (*old_cmd == '\0') { + return FALSE; + } + + old_args = g_strjoinv (" ", (char**) argv + 1); + new_cmd = g_strdup_printf ("tracker %s %s", old_cmd, old_args); + g_free (old_args); + + *new_argv = g_strsplit (new_cmd, " ", -1); + *new_argc = argc + 1; + g_free (new_cmd); + + return TRUE; +} + +gboolean +tracker_compatible (int argc, + const char **argv, + int *new_argc, + char ***new_argv) +{ + *new_argc = 0; + *new_argv = NULL; + + /* + * Conversions: + * $ tracker-control + * --list-processes | -p --> 'tracker daemon $same_args' + * --kill | -k --> 'tracker daemon $same_args' + * --terminate | -t --> 'tracker daemon $same_args' + * --hard-reset | -r --> 'tracker reset --hard | -r' + * --soft-reset | -e --> 'tracker reset --soft | -e' + * --remove-config | -c --> 'tracker reset --config | -c' + * --start | -s --> 'tracker daemon $same_args' + * --backup | -b --> 'tracker index $same_args' + * --restore | -o --> 'tracker index $same_args' + * --set-log-verbosity --> 'tracker daemon $same_args' + * --get-log-verbosity --> 'tracker daemon $same_args' + * --collect-debug-info --> 'tracker status $same_args' + * --watch | -w --> 'tracker daemon --watch | -w' + * --follow | -F --> 'tracker daemon --follow | -f' + * --list-common-statuses --> 'tracker daemon $same_args' + * --list-miners-running --> 'tracker daemon $same_args' + * --list-miners-available --> 'tracker daemon $same_args' + * --miner --> 'tracker daemon $same_args' + * --pause-details --> 'tracker daemon $same_args' + * --pause --> 'tracker daemon $same_args' + * --pause-for-process --> 'tracker daemon $same_args' + * --resume --> 'tracker daemon $same_args' + * --status | -S --> 'tracker daemon' (no args) + * --reindex-mime-type | -m --> 'tracker index $same_args' + * --index-file | -f --> 'tracker index --file | -f' + * + * $ tracker-stats --> 'tracker status --stat $same_args' + * + * $ tracker-import --> 'tracker index --import | -i' + * + */ + if (strcmp (argv[0], "stats") == 0) { + prepend_args ("status --stat", 1, 1, argc, argv, new_argc, new_argv); + return TRUE; + } else if (strcmp (argv[0], "import") == 0) { + prepend_args ("index --import", 1, 1, argc, argv, new_argc, new_argv); + return TRUE; + } else if (strcmp (argv[0], "control") == 0) { + if (find_arg ("--list-processes", "-p", argc, argv) || + find_arg ("--kill", "-k", argc, argv) || + find_arg ("--terminate", "-t", argc, argv) || + find_arg ("--start", "-s", argc, argv) || + find_arg ("--set-log-verbosity", NULL, argc, argv) || + find_arg ("--get-log-verbosity", NULL, argc, argv) || + find_arg ("--watch", "-w", argc, argv) || + find_arg ("--list-common-statuses", NULL, argc, argv) || + find_arg ("--list-miners-running", NULL, argc, argv) || + find_arg ("--list-miners-available", NULL, argc, argv) || + find_arg ("--miner", NULL, argc, argv) || + find_arg ("--pause-details", NULL, argc, argv) || + find_arg ("--pause", NULL, argc, argv) || + find_arg ("--pause-for-process", NULL, argc, argv) || + find_arg ("--resume", NULL, argc, argv)) { + argv[0] = "daemon"; + return FALSE; + } else if (find_arg ("--follow", "-F", argc, argv)) { + /* Previously, we had -F, now we support -f */ + *new_argv = g_strsplit ("daemon --follow", " ", -1); + *new_argc = 2; + return TRUE; + } else if (find_arg ("--collect-debug-info", NULL, argc, argv)) { + argv[0] = "status"; + return FALSE; + } else if (find_arg ("--hard-reset", "-r", argc, argv)) { + *new_argv = g_strsplit ("reset --hard", " ", -1); + *new_argc = 2; + return TRUE; + } else if (find_arg ("--soft-reset", "-e", argc, argv)) { + *new_argv = g_strsplit ("reset --soft", " ", -1); + *new_argc = 2; + return TRUE; + } else if (find_arg ("--remove-config", "-c", argc, argv)) { + *new_argv = g_strsplit ("reset --config", " ", -1); + *new_argc = 2; + return TRUE; + } else if (find_arg ("--backup", "-b", argc, argv)) { + prepend_args ("index --backup", 1, 1, argc, argv, new_argc, new_argv); + return TRUE; + } else if (find_arg ("--restore", "-o", argc, argv)) { + prepend_args ("index --restore", 1, 1, argc, argv, new_argc, new_argv); + return TRUE; + } else if (find_arg ("--reindex-mime-type", "-m", argc, argv)) { + prepend_args ("index --reindex-mime-type", 1, 1, argc, argv, new_argc, new_argv); + return TRUE; + } else if (find_arg ("--index-file", "-f", argc, argv)) { + prepend_args ("index --file", 1, 1, argc, argv, new_argc, new_argv); + return TRUE; + } else if (find_arg ("--help", "-h", argc, argv)) { + g_printerr ("%s\n\n", + _("The 'tracker-control' command is no longer available")); + *new_argv = g_strsplit ("daemon -h", " ", -1); + *new_argc = 2; + return TRUE; + } else { + /* This includes --status and -S */ + *new_argv = g_strsplit ("daemon", " ", -1); + *new_argc = 1; + return TRUE; + } + } + + /* Return TRUE if we have new argv/argc, otherwise FALSE */ + return FALSE; +} diff --git a/src/tracker/tracker-compatible.h b/src/tracker/tracker-compatible.h new file mode 100644 index 000000000..6835973c1 --- /dev/null +++ b/src/tracker/tracker-compatible.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2014, Lanedo <martyn@lanedo.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __TRACKER_COMPATIBLE_H__ +#define __TRACKER_COMPATIBLE_H__ + +gboolean tracker_compatible_commands (int argc, const char **argv, int *new_argc, char ***new_argv); +gboolean tracker_compatible (int argc, const char **argv, int * new_argc, char ***new_argv); + +#endif /* __TRACKER_COMPATIBLE_H__ */ diff --git a/src/tracker/tracker-main.c b/src/tracker/tracker-main.c index 0f8f8c712..0a86ad57e 100644 --- a/src/tracker/tracker-main.c +++ b/src/tracker/tracker-main.c @@ -29,6 +29,7 @@ #include <libtracker-common/tracker-common.h> #include "tracker-daemon.h" +#include "tracker-compatible.h" #include "tracker-help.h" #include "tracker-index.h" #include "tracker-info.h" @@ -195,9 +196,12 @@ print_usage (void) } int -main (int argc, char **av) +main (int original_argc, char **original_argv) { - const char **argv = (const char **) av; + int new_argc = 0; + char **new_argv = NULL; + const char **argv = (const char **) original_argv; + int argc = original_argc; setlocale (LC_ALL, ""); @@ -205,6 +209,12 @@ main (int argc, char **av) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); + /* Handle old commands symlinked */ + if (tracker_compatible_commands (argc, argv, &new_argc, &new_argv)) { + argv = (const char **) new_argv; + argc = new_argc; + } + argv++; argc--; @@ -212,6 +222,12 @@ main (int argc, char **av) /* For cases like --version */ if (g_str_has_prefix (argv[0], "--")) { argv[0] += 2; + } else { + /* Check for compatibility changes necessary before continuing */ + if (tracker_compatible (argc, argv, &new_argc, &new_argv)) { + argv = (const char **) new_argv; + argc = new_argc; + } } } else { /* The user didn't specify a command; give them help */ @@ -221,5 +237,9 @@ main (int argc, char **av) handle_command (argc, argv); + if ((char **) argv != original_argv) { + g_strfreev ((char **) argv); + } + return EXIT_FAILURE; } |