Blame SOURCES/0173-uploader-save-remote-name-in-reported_to.patch

4b6aa8
From 41c56564e18a303a75584f1f65626d37d7ee5c54 Mon Sep 17 00:00:00 2001
4b6aa8
From: Jakub Filak <jfilak@redhat.com>
4b6aa8
Date: Mon, 19 Oct 2015 14:46:16 +0200
4b6aa8
Subject: [PATCH] uploader: save remote name in reported_to
4b6aa8
4b6aa8
All other plugins do so. We also need this commit to be able to attach
4b6aa8
URLs to uploaded dump directories to uReport on FAF servers.
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
---
4b6aa8
 src/plugins/reporter-upload.c | 55 ++++++++++++++++++++++++++++++-------------
4b6aa8
 1 file changed, 38 insertions(+), 17 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/plugins/reporter-upload.c b/src/plugins/reporter-upload.c
4b6aa8
index b148d95..971c5c1 100644
4b6aa8
--- a/src/plugins/reporter-upload.c
4b6aa8
+++ b/src/plugins/reporter-upload.c
4b6aa8
@@ -32,7 +32,7 @@ static char *ask_url(const char *message)
4b6aa8
     return url;
4b6aa8
 }
4b6aa8
 
4b6aa8
-static int interactive_upload_file(const char *url, const char *file_name)
4b6aa8
+static int interactive_upload_file(const char *url, const char *file_name, char **remote_name)
4b6aa8
 {
4b6aa8
     post_state_t *state = new_post_state(POST_WANT_ERROR_MSG);
4b6aa8
     state->username = getenv("Upload_Username");
4b6aa8
@@ -53,19 +53,24 @@ static int interactive_upload_file(const char *url, const char *file_name)
4b6aa8
         }
4b6aa8
     }
4b6aa8
 
4b6aa8
-    char *remote_name = upload_file_ext(state, url, file_name, UPLOAD_FILE_HANDLE_ACCESS_DENIALS);
4b6aa8
-    int result = (remote_name == NULL); /* error if NULL */
4b6aa8
+    char *tmp = upload_file_ext(state, url, file_name, UPLOAD_FILE_HANDLE_ACCESS_DENIALS);
4b6aa8
+
4b6aa8
+    if (remote_name)
4b6aa8
+        *remote_name = tmp;
4b6aa8
+    else
4b6aa8
+        free(tmp);
4b6aa8
 
4b6aa8
-    free(remote_name);
4b6aa8
     free(password_inp);
4b6aa8
     free_post_state(state);
4b6aa8
 
4b6aa8
-    return result;
4b6aa8
+    /* return 0 on success */
4b6aa8
+    return tmp == NULL;
4b6aa8
 }
4b6aa8
 
4b6aa8
 static int create_and_upload_archive(
4b6aa8
                 const char *dump_dir_name,
4b6aa8
-                map_string_t *settings)
4b6aa8
+                const char *url,
4b6aa8
+                char **remote_name)
4b6aa8
 {
4b6aa8
     int result = 1; /* error */
4b6aa8
 
4b6aa8
@@ -78,11 +83,6 @@ static int create_and_upload_archive(
4b6aa8
     tempfile = concat_path_basename(LARGE_DATA_TMP_DIR, dump_dir_name);
4b6aa8
     tempfile = append_to_malloced_string(tempfile, ".tar.gz");
4b6aa8
 
4b6aa8
-    const char* opt = getenv("Upload_URL");
4b6aa8
-    if (!opt)
4b6aa8
-        opt = get_map_string_item_or_empty(settings, "URL");
4b6aa8
-    char *url = opt[0] != '\0' ? xstrdup(opt) : ask_url(_("Please enter a URL (scp, ftp, etc.) where the problem data is to be exported:"));
4b6aa8
-
4b6aa8
     string_vector_ptr_t exclude_from_report = get_global_always_excluded_elements();
4b6aa8
     struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
4b6aa8
     if (!dd)
4b6aa8
@@ -102,17 +102,16 @@ static int create_and_upload_archive(
4b6aa8
     /* Upload the archive */
4b6aa8
     /* Upload from /tmp to /tmp + deletion -> BAD, exclude this possibility */
4b6aa8
     if (url && url[0] && strcmp(url, "file://"LARGE_DATA_TMP_DIR"/") != 0)
4b6aa8
-        result = interactive_upload_file(url, tempfile);
4b6aa8
+        result = interactive_upload_file(url, tempfile, remote_name);
4b6aa8
     else
4b6aa8
     {
4b6aa8
         result = 0; /* success */
4b6aa8
         log(_("Archive is created: '%s'"), tempfile);
4b6aa8
-        free(tempfile);
4b6aa8
+        *remote_name = tempfile;
4b6aa8
         tempfile = NULL;
4b6aa8
     }
4b6aa8
 
4b6aa8
  ret:
4b6aa8
-    free(url);
4b6aa8
     dd_close(dd);
4b6aa8
 
4b6aa8
     if (tempfile)
4b6aa8
@@ -192,13 +191,35 @@ int main(int argc, char **argv)
4b6aa8
     //ExcludeFiles = foo,bar*,b*z
4b6aa8
 
4b6aa8
     map_string_t *settings = new_map_string();
4b6aa8
-    if (url)
4b6aa8
-        replace_map_string_item(settings, xstrdup("URL"), xstrdup(url));
4b6aa8
     if (conf_file)
4b6aa8
         load_conf_file(conf_file, settings, /*skip key w/o values:*/ false);
4b6aa8
 
4b6aa8
-    int result = create_and_upload_archive(dump_dir_name, settings);
4b6aa8
+    char *input_url = NULL;
4b6aa8
+    const char *conf_url = getenv("Upload_URL");
4b6aa8
+    if (!conf_url || conf_url[0] == '\0')
4b6aa8
+        conf_url = url;
4b6aa8
+    if (!conf_url || conf_url[0] == '\0')
4b6aa8
+        conf_url = get_map_string_item_or_empty(settings, "URL");
4b6aa8
+    if (!conf_url || conf_url[0] == '\0')
4b6aa8
+        conf_url = input_url = ask_url(_("Please enter a URL (scp, ftp, etc.) where the problem data is to be exported:"));
4b6aa8
+
4b6aa8
+    char *remote_name = NULL;
4b6aa8
+    const int result = create_and_upload_archive(dump_dir_name, conf_url, &remote_name);
4b6aa8
+    if (result != 0)
4b6aa8
+        goto finito;
4b6aa8
+
4b6aa8
+    struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
4b6aa8
+    if (dd)
4b6aa8
+    {
4b6aa8
+        report_result_t rr = { .label = (char *)"upload" };
4b6aa8
+        rr.url = remote_name,
4b6aa8
+        add_reported_to_entry(dd, &rr);
4b6aa8
+        dd_close(dd);
4b6aa8
+    }
4b6aa8
+    free(remote_name);
4b6aa8
 
4b6aa8
+finito:
4b6aa8
+    free(input_url);
4b6aa8
     free_map_string(settings);
4b6aa8
     return result;
4b6aa8
 }
4b6aa8
-- 
4b6aa8
1.8.3.1
4b6aa8