mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
tempfile.mkstemp() actually returns a file descriptor which should be closed. (#35263)
This commit is contained in:
parent
798cd41b34
commit
0f17d74f0f
1 changed files with 7 additions and 3 deletions
|
@ -315,12 +315,16 @@ def write_file(module, dest, content):
|
|||
has changed.
|
||||
'''
|
||||
changed = False
|
||||
# create a tempfile with some test content
|
||||
_, tmpsrc = tempfile.mkstemp()
|
||||
f = open(tmpsrc, 'wb')
|
||||
# create a tempfile
|
||||
fd, tmpsrc = tempfile.mkstemp(text=False)
|
||||
f = os.fdopen(fd, 'wb')
|
||||
try:
|
||||
f.write(content)
|
||||
except Exception as err:
|
||||
try:
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
os.remove(tmpsrc)
|
||||
module.fail_json(msg="failed to create temporary content file: %s" % to_native(err), exception=traceback.format_exc())
|
||||
f.close()
|
||||
|
|
Loading…
Reference in a new issue