Use context manager for file handling in some system modules. (#65227)

pull/75678/head
Mads Jensen 4 years ago committed by GitHub
parent 9c2f44b884
commit d6dededab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- system_service - use a context manager for file handling.

@ -385,7 +385,7 @@ class Service(object):
self.changed = None self.changed = None
entry = '%s="%s"\n' % (self.rcconf_key, self.rcconf_value) entry = '%s="%s"\n' % (self.rcconf_key, self.rcconf_value)
RCFILE = open(self.rcconf_file, "r") with open(self.rcconf_file, "r") as RCFILE:
new_rc_conf = [] new_rc_conf = []
# Build a list containing the possibly modified file. # Build a list containing the possibly modified file.
@ -407,9 +407,6 @@ class Service(object):
# Add line to the list. # Add line to the list.
new_rc_conf.append(rcline.strip() + '\n') new_rc_conf.append(rcline.strip() + '\n')
# We are done with reading the current rc.conf, close it.
RCFILE.close()
# If we did not see any trace of our entry we need to add it. # If we did not see any trace of our entry we need to add it.
if self.changed is None: if self.changed is None:
new_rc_conf.append(entry) new_rc_conf.append(entry)

Loading…
Cancel
Save