mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Close all open filehandle (#50544)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
94a1d86d70
commit
db8702cdb8
21 changed files with 81 additions and 47 deletions
|
@ -108,7 +108,8 @@ def get_matching_jobs(module, at_cmd, script_file):
|
|||
return matching_jobs
|
||||
|
||||
# Read script_file into a string.
|
||||
script_file_string = open(script_file).read().strip()
|
||||
with open(script_file) as script_fh:
|
||||
script_file_string = script_fh.read().strip()
|
||||
|
||||
# Loop through the jobs.
|
||||
# If the script text is contained in a job add job number to list.
|
||||
|
|
|
@ -686,12 +686,15 @@ class LinuxService(Service):
|
|||
override_file_name = "%s/%s.override" % (initpath, self.name)
|
||||
|
||||
# Check to see if files contain the manual line in .conf and fail if True
|
||||
if manreg.search(open(conf_file_name).read()):
|
||||
with open(conf_file_name) as conf_file_fh:
|
||||
conf_file_content = conf_file_fh.read()
|
||||
if manreg.search(conf_file_content):
|
||||
self.module.fail_json(msg="manual stanza not supported in a .conf file")
|
||||
|
||||
self.changed = False
|
||||
if os.path.exists(override_file_name):
|
||||
override_file_contents = open(override_file_name).read()
|
||||
with open(override_file_name) as override_fh:
|
||||
override_file_contents = override_fh.read()
|
||||
# Remove manual stanza if present and service enabled
|
||||
if self.enable and manreg.search(override_file_contents):
|
||||
self.changed = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue