mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-30 12:10:22 -07:00
ios_file: Don't leave leftover files behind (#42622)
* Don't leave leftover files behind * Fix writing files in python3 * Replace nonascii.bin with one that will not pass for unicode
This commit is contained in:
parent
6a94090e7f
commit
6b162142a7
4 changed files with 28 additions and 22 deletions
|
@ -83,9 +83,13 @@ class ActionModule(ActionBase):
|
|||
src = self._task.args.get('src')
|
||||
filename = str(uuid.uuid4())
|
||||
cwd = self._loader.get_basedir()
|
||||
output_file = cwd + '/' + filename
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(src)
|
||||
output_file = os.path.join(cwd, filename)
|
||||
try:
|
||||
with open(output_file, 'wb') as f:
|
||||
f.write(to_bytes(src, encoding='utf-8'))
|
||||
except Exception:
|
||||
os.remove(output_file)
|
||||
raise
|
||||
else:
|
||||
try:
|
||||
output_file = self._get_binary_src_file(src)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue