From 9f58e69d63264574d3ad3704749fb86e50859f77 Mon Sep 17 00:00:00 2001 From: Irina Muchnik Date: Sat, 10 Dec 2016 06:33:34 -0800 Subject: [PATCH] Fix secure temp file creation (#19096) * For realz this time * Fix tempfile.mkstemp (#2) * back to square one, removing temp file from the mix * Adding temp back * Adding tuple back * Adding another tuple back * Trying to get around weird Jenkins behavior of blowing up when both .hpi and jpi file found * Incorporating PR feedback * Delete .hpi file instead of backing it up, some basic clean up * Moving file deletion to the right location * Blank lines. They always get me. --- .../modules/web_infrastructure/jenkins_plugin.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py index 56067c38a6..832dbe060a 100644 --- a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py +++ b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py @@ -442,6 +442,13 @@ class JenkinsPlugin(object): msg_exception="Plugin installation has failed.", data=data) + hpi_file = '%s/plugins/%s.hpi' % ( + self.params['jenkins_home'], + self.params['name']) + + if os.path.isfile(hpi_file): + os.remove(hpi_file) + changed = True else: # Check if the plugin directory exists @@ -567,7 +574,7 @@ class JenkinsPlugin(object): msg_exception="Updates download failed.") # Write the updates file - updates_file = tempfile.mkstemp() + update_fd, updates_file = tempfile.mkstemp() try: fd = open(updates_file, 'wb') @@ -644,7 +651,7 @@ class JenkinsPlugin(object): def _write_file(self, f, data): # Store the plugin into a temp file and then move it - tmp_f = tempfile.mkstemp() + tmp_f_tuple, tmp_f = tempfile.mkstemp() try: fd = open(tmp_f, 'wb')