Blame SOURCES/0146-cli-use-internal-command-impl-in-the-command-process.patch

baab13
From 408a012dabf4c43cfb34dfb9547f9d908a521fec Mon Sep 17 00:00:00 2001
baab13
From: Jakub Filak <jfilak@redhat.com>
baab13
Date: Thu, 9 Jul 2015 11:54:36 +0200
baab13
Subject: [PATCH] cli: use internal command impl in the command process
baab13
baab13
It did not seem to be a good idea to add wrappers for the internal
baab13
commands, because the wrappers would be one line functions. Now, we need
baab13
to do more sophisticated processing (authenticate, chown), so adding the
baab13
wrappers is the best choice to provide the same functionality in the
baab13
command process.
baab13
baab13
Related: #1224984
baab13
baab13
Signed-off-by: Jakub Filak <jfilak@redhat.com>
baab13
---
baab13
 src/cli/builtin-cmd.h |  3 +++
baab13
 src/cli/list.c        |  8 ++++++-
baab13
 src/cli/process.c     | 16 ++++---------
baab13
 src/cli/report.c      | 65 +++++++++++++++++++++++++++------------------------
baab13
 src/cli/rm.c          |  7 +++++-
baab13
 5 files changed, 56 insertions(+), 43 deletions(-)
baab13
baab13
diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
baab13
index bc80479..c6cd691 100644
baab13
--- a/src/cli/builtin-cmd.h
baab13
+++ b/src/cli/builtin-cmd.h
baab13
@@ -22,8 +22,11 @@
baab13
 
baab13
 extern int cmd_list(int argc, const char **argv);
baab13
 extern int cmd_remove(int argc, const char **argv);
baab13
+extern int _cmd_remove(const char **dirs_strv);
baab13
 extern int cmd_report(int argc, const char **argv);
baab13
+extern int _cmd_report(const char **dirs_strv, int remove);
baab13
 extern int cmd_info(int argc, const char **argv);
baab13
+extern int _cmd_info(problem_data_t *problem_data, int detailed, int text_size);
baab13
 extern int cmd_status(int argc, const char **argv);
baab13
 extern int cmd_process(int argc, const char **argv);
baab13
 
baab13
diff --git a/src/cli/list.c b/src/cli/list.c
baab13
index 49c3e30..c76e4fb 100644
baab13
--- a/src/cli/list.c
baab13
+++ b/src/cli/list.c
baab13
@@ -217,6 +217,12 @@ int cmd_list(int argc, const char **argv)
baab13
     return 0;
baab13
 }
baab13
 
baab13
+int _cmd_info(problem_data_t *problem_data, int detailed, int text_size)
baab13
+{
baab13
+    print_crash(problem_data, detailed, text_size);
baab13
+    return 0;
baab13
+}
baab13
+
baab13
 int cmd_info(int argc, const char **argv)
baab13
 {
baab13
     const char *program_usage_string = _(
baab13
@@ -254,7 +260,7 @@ int cmd_info(int argc, const char **argv)
baab13
             continue;
baab13
         }
baab13
 
baab13
-        print_crash(problem, opt_detailed, text_size);
baab13
+        _cmd_info(problem, opt_detailed, text_size);
baab13
         problem_data_free(problem);
baab13
         if (*argv)
baab13
             printf("\n");
baab13
diff --git a/src/cli/process.c b/src/cli/process.c
baab13
index 39462f9..401ef60 100644
baab13
--- a/src/cli/process.c
baab13
+++ b/src/cli/process.c
baab13
@@ -68,28 +68,22 @@ static int process_one_crash(problem_data_t *problem_data)
baab13
         if(strcmp(action, "rm") == 0 || strcmp(action, "remove") == 0 )
baab13
         {
baab13
             log(_("Deleting '%s'"), dir_name);
baab13
-            delete_dump_dir_possibly_using_abrtd(dir_name);
baab13
+            const char *dirs_strv[] = {dir_name, NULL};
baab13
+            _cmd_remove(dirs_strv);
baab13
 
baab13
             ret_val = ACT_REMOVE;
baab13
         }
baab13
         else if (not_reportable == NULL && (strcmp(action, "e") == 0 || strcmp(action, "report") == 0))
baab13
         {
baab13
             log(_("Reporting '%s'"), dir_name);
baab13
-            report_problem_in_dir(dir_name,
baab13
-                                     LIBREPORT_WAIT
baab13
-                                   | LIBREPORT_RUN_CLI);
baab13
+            const char *dirs_strv[] = {dir_name, NULL};
baab13
+            _cmd_report(dirs_strv, /*do not delete*/0);
baab13
 
baab13
             ret_val = ACT_REPORT;
baab13
         }
baab13
         else if (strcmp(action, "i") == 0 || strcmp(action, "info") == 0)
baab13
         {
baab13
-            char *desc = make_description(problem_data,
baab13
-                                    /*names_to_skip:*/ NULL,
baab13
-                                    /*max_text_size:*/ CD_TEXT_ATT_SIZE_BZ,
baab13
-                                    MAKEDESC_SHOW_FILES | MAKEDESC_SHOW_MULTILINE);
baab13
-
baab13
-            fputs(desc, stdout);
baab13
-            free(desc);
baab13
+            _cmd_info(problem_data, /*detailed*/1, CD_TEXT_ATT_SIZE_BZ);
baab13
 
baab13
             ret_val = ACT_INFO;
baab13
         }
baab13
diff --git a/src/cli/report.c b/src/cli/report.c
baab13
index 194f7c9..19b4c51 100644
baab13
--- a/src/cli/report.c
baab13
+++ b/src/cli/report.c
baab13
@@ -22,38 +22,12 @@
baab13
 #include "abrt-cli-core.h"
baab13
 #include "builtin-cmd.h"
baab13
 
baab13
-int cmd_report(int argc, const char **argv)
baab13
+int _cmd_report(const char **dirs_strv, int remove)
baab13
 {
baab13
-    const char *program_usage_string = _(
baab13
-        "& report [options] DIR..."
baab13
-    );
baab13
-
baab13
-    enum {
baab13
-        OPT_v = 1 << 0,
baab13
-        OPT_d = 1 << 1,
baab13
-    };
baab13
-
baab13
-    struct options program_options[] = {
baab13
-        OPT__VERBOSE(&g_verbose),
baab13
-        OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
baab13
-        OPT_END()
baab13
-    };
baab13
-
baab13
-    unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
baab13
-    argv += optind;
baab13
-
baab13
-    if (!argv[0])
baab13
-        show_usage_and_die(program_usage_string, program_options);
baab13
-
baab13
-    export_abrt_envvars(/*prog_prefix:*/ 0);
baab13
-
baab13
-    load_abrt_conf();
baab13
-    free_abrt_conf_data();
baab13
-
baab13
     int ret = 0;
baab13
-    while (*argv)
baab13
+    while (*dirs_strv)
baab13
     {
baab13
-        const char *dir_name = *argv++;
baab13
+        const char *dir_name = *dirs_strv++;
baab13
         char *const real_problem_id = hash2dirname_if_necessary(dir_name);
baab13
         if (real_problem_id == NULL)
baab13
         {
baab13
@@ -75,7 +49,7 @@ int cmd_report(int argc, const char **argv)
baab13
                                            | LIBREPORT_RUN_CLI);
baab13
 
baab13
         /* the problem was successfully reported and option is -d */
baab13
-        if((opts & OPT_d) && (status == 0 || status == EXIT_STOP_EVENT_RUN))
baab13
+        if(remove && (status == 0 || status == EXIT_STOP_EVENT_RUN))
baab13
         {
baab13
             log(_("Deleting '%s'"), real_problem_id);
baab13
             delete_dump_dir_possibly_using_abrtd(real_problem_id);
baab13
@@ -89,3 +63,34 @@ int cmd_report(int argc, const char **argv)
baab13
 
baab13
     return ret;
baab13
 }
baab13
+
baab13
+int cmd_report(int argc, const char **argv)
baab13
+{
baab13
+    const char *program_usage_string = _(
baab13
+        "& report [options] DIR..."
baab13
+    );
baab13
+
baab13
+    enum {
baab13
+        OPT_v = 1 << 0,
baab13
+        OPT_d = 1 << 1,
baab13
+    };
baab13
+
baab13
+    struct options program_options[] = {
baab13
+        OPT__VERBOSE(&g_verbose),
baab13
+        OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
baab13
+        OPT_END()
baab13
+    };
baab13
+
baab13
+    unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
baab13
+    argv += optind;
baab13
+
baab13
+    if (!argv[0])
baab13
+        show_usage_and_die(program_usage_string, program_options);
baab13
+
baab13
+    export_abrt_envvars(/*prog_prefix:*/ 0);
baab13
+
baab13
+    load_abrt_conf();
baab13
+    free_abrt_conf_data();
baab13
+
baab13
+    return _cmd_report(argv, opts & OPT_d);
baab13
+}
baab13
diff --git a/src/cli/rm.c b/src/cli/rm.c
baab13
index 37d50e2..95ae097 100644
baab13
--- a/src/cli/rm.c
baab13
+++ b/src/cli/rm.c
baab13
@@ -52,6 +52,11 @@ static int remove_using_abrtd_or_fs(const char **dirs_strv)
baab13
     return errs;
baab13
 }
baab13
 
baab13
+int _cmd_remove(const char **dirs_strv)
baab13
+{
baab13
+    return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(dirs_strv);
baab13
+}
baab13
+
baab13
 int cmd_remove(int argc, const char **argv)
baab13
 {
baab13
     const char *program_usage_string = _(
baab13
@@ -69,5 +74,5 @@ int cmd_remove(int argc, const char **argv)
baab13
     if (!argv[0])
baab13
         show_usage_and_die(program_usage_string, program_options);
baab13
 
baab13
-    return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(argv);
baab13
+    return _cmd_remove(argv);
baab13
 }
baab13
-- 
baab13
2.4.3
baab13