From bcdcc428a604afc36e5d0a2f697ed9d2886413a6 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 27 Jan 2019 01:36:52 +0100 Subject: [PATCH] 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. --- src/borg/cache.py | 3 ++- src/borg/repository.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/borg/cache.py b/src/borg/cache.py index d792f5204..1ae2c4f67 100644 --- a/src/borg/cache.py +++ b/src/borg/cache.py @@ -263,7 +263,8 @@ class CacheConfig: def load(self): 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.id = self._config.get('cache', 'repository') self.manifest_id = unhexlify(self._config.get('cache', 'manifest')) diff --git a/src/borg/repository.py b/src/borg/repository.py index 1a9ce9acc..31e74af3c 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -382,7 +382,8 @@ class Repository: else: self.lock = 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: self.close() raise self.InvalidRepository(path)