1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 18:28:42 +00:00

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 b8fe7b6b83
commit b4c68de128
2 changed files with 4 additions and 2 deletions

View file

@ -262,7 +262,8 @@ def open(self):
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

@ -383,7 +383,8 @@ def open(self, path, exclusive, lock_wait=None, lock=True):
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)