浏览代码

Merge pull request #4271 from ThomasWaldmann/fix-configparser-diaper-master

avoid diaper pattern in configparser by opening files, fixes #4263
TW 6 年之前
父节点
当前提交
45382e0fd3
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 2 1
      src/borg/cache.py
  2. 2 1
      src/borg/repository.py

+ 2 - 1
src/borg/cache.py

@@ -262,7 +262,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'))

+ 2 - 1
src/borg/repository.py

@@ -383,7 +383,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)