Skip to content

Commit 9574f88

Browse files
committed
Bug 1830961 - Explicitly close IO objects opened by mozversion, r=ahal
Differential Revision: https://phabricator.services.mozilla.com/D176990
1 parent 0671799 commit 9574f88

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

testing/mozbase/mozversion/mozversion/mozversion.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ def get_gecko_info(self, path):
2727
for type, section in INI_DATA_MAPPING:
2828
config_file = os.path.join(path, "%s.ini" % type)
2929
if os.path.exists(config_file):
30-
self._parse_ini_file(open(config_file), type, section)
30+
try:
31+
with open(config_file) as fp:
32+
self._parse_ini_file(fp, type, section)
33+
except OSError:
34+
self._logger.warning("Unable to read %s" % config_file)
3135
else:
3236
self._logger.warning("Unable to find %s" % config_file)
3337

3438
def _parse_ini_file(self, fp, type, section):
3539
config = configparser.RawConfigParser()
36-
config.readfp(fp)
40+
config.read_file(fp)
3741
name_map = {
3842
"codename": "display_name",
3943
"milestone": "version",
@@ -61,14 +65,14 @@ def get_gecko_info(self, path):
6165
for type, section in INI_DATA_MAPPING:
6266
filename = "%s.ini" % type
6367
if filename in archive_list:
64-
fp = io.TextIOWrapper(archive.open(filename))
65-
self._parse_ini_file(fp, type, section)
68+
with io.TextIOWrapper(archive.open(filename)) as fp:
69+
self._parse_ini_file(fp, type, section)
6670
else:
6771
self._logger.warning("Unable to find %s" % filename)
6872

6973
if "package-name.txt" in archive_list:
70-
fp = io.TextIOWrapper(archive.open("package-name.txt"))
71-
self._info["package_name"] = fp.readlines()[0].strip()
74+
with io.TextIOWrapper(archive.open("package-name.txt")) as fp:
75+
self._info["package_name"] = fp.readlines()[0].strip()
7276

7377

7478
class LocalVersion(Version):

0 commit comments

Comments
 (0)