avoid diaper pattern in configparser by opening files, fixes #4263

this will fail early with correct error msg / exception traceback
if a config file is not readable.
This commit is contained in:
Thomas Waldmann 2019-01-27 01:36:52 +01:00
parent 659a69a33d
commit bcdcc428a6
2 changed files with 4 additions and 2 deletions

View File

@ -263,7 +263,8 @@ class CacheConfig:
def load(self): def load(self):
self._config = configparser.ConfigParser(interpolation=None) self._config = configparser.ConfigParser(interpolation=None)
self._config.read(self.config_path) with open(self.config_path) as fd:
self._config.read_file(fd)
self._check_upgrade(self.config_path) self._check_upgrade(self.config_path)
self.id = self._config.get('cache', 'repository') self.id = self._config.get('cache', 'repository')
self.manifest_id = unhexlify(self._config.get('cache', 'manifest')) self.manifest_id = unhexlify(self._config.get('cache', 'manifest'))

View File

@ -382,7 +382,8 @@ class Repository:
else: else:
self.lock = None self.lock = None
self.config = ConfigParser(interpolation=None) self.config = ConfigParser(interpolation=None)
self.config.read(os.path.join(self.path, 'config')) with open(os.path.join(self.path, 'config')) as fd:
self.config.read_file(fd)
if 'repository' not in self.config.sections() or self.config.getint('repository', 'version') != 1: if 'repository' not in self.config.sections() or self.config.getint('repository', 'version') != 1:
self.close() self.close()
raise self.InvalidRepository(path) raise self.InvalidRepository(path)