Use context manager in yum module. (#65376)

pull/68552/head
Mads Jensen 5 years ago committed by GitHub
parent 8077d8e401
commit eaf648e600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- packaging_yum - replace legacy file handling with a file manager.

@ -506,19 +506,11 @@ class YumRepo(object):
if len(self.repofile.sections()):
# Write data into the file
try:
fd = open(self.params['dest'], 'w')
with open(self.params['dest'], 'w') as fd:
self.repofile.write(fd)
except IOError as e:
self.module.fail_json(
msg="Cannot open repo file %s." % self.params['dest'],
details=to_native(e))
self.repofile.write(fd)
try:
fd.close()
except IOError as e:
self.module.fail_json(
msg="Cannot write repo file %s." % self.params['dest'],
msg="Problems handling file %s." % self.params['dest'],
details=to_native(e))
else:
# Remove the file if there are not repos

Loading…
Cancel
Save