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

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