Use context manager in yum module. (#65376)
This commit is contained in:
parent
8077d8e401
commit
eaf648e600
2 changed files with 5 additions and 11 deletions
2
changelogs/fragments/65376.yaml
Normal file
2
changelogs/fragments/65376.yaml
Normal file
|
@ -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…
Reference in a new issue