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

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