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

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