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