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

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