浏览代码

repository: create and use version 2 repos only for now

for now, this code shall only work on v2 repos (created by this code).

the code to read v1 repos is still present though, so for experiments,
it is possible to change the repo version in the repo config from 1 to
2 manually.

having version 2 in the repo config also avoids that borg < 1.3 is
used on such a repo, which would cause damage:
old borg would not recognize the PUT2 tagged segment entries and
old borg check --repair would likely kill them all due to that.

also: keep repo version in Repository.version
Thomas Waldmann 3 年之前
父节点
当前提交
38f390ae45
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      src/borg/repository.py

+ 8 - 2
src/borg/repository.py

@@ -165,6 +165,7 @@ class Repository:
                  make_parent_dirs=False):
                  make_parent_dirs=False):
         self.path = os.path.abspath(path)
         self.path = os.path.abspath(path)
         self._location = Location('file://%s' % self.path)
         self._location = Location('file://%s' % self.path)
+        self.version = None
         self.io = None  # type: LoggedIO
         self.io = None  # type: LoggedIO
         self.lock = None
         self.lock = None
         self.index = None
         self.index = None
@@ -286,7 +287,8 @@ class Repository:
         os.mkdir(os.path.join(path, 'data'))
         os.mkdir(os.path.join(path, 'data'))
         config = ConfigParser(interpolation=None)
         config = ConfigParser(interpolation=None)
         config.add_section('repository')
         config.add_section('repository')
-        config.set('repository', 'version', '1')
+        self.version = 2
+        config.set('repository', 'version', str(self.version))
         config.set('repository', 'segments_per_dir', str(DEFAULT_SEGMENTS_PER_DIR))
         config.set('repository', 'segments_per_dir', str(DEFAULT_SEGMENTS_PER_DIR))
         config.set('repository', 'max_segment_size', str(DEFAULT_MAX_SEGMENT_SIZE))
         config.set('repository', 'max_segment_size', str(DEFAULT_MAX_SEGMENT_SIZE))
         config.set('repository', 'append_only', str(int(self.append_only)))
         config.set('repository', 'append_only', str(int(self.append_only)))
@@ -442,7 +444,11 @@ class Repository:
         except FileNotFoundError:
         except FileNotFoundError:
             self.close()
             self.close()
             raise self.InvalidRepository(self.path)
             raise self.InvalidRepository(self.path)
-        if 'repository' not in self.config.sections() or self.config.getint('repository', 'version') != 1:
+        if 'repository' not in self.config.sections():
+            self.close()
+            raise self.InvalidRepository(path)
+        self.version = self.config.getint('repository', 'version')
+        if self.version not in (2, ):  # for now, only work on new repos
             self.close()
             self.close()
             raise self.InvalidRepository(path)
             raise self.InvalidRepository(path)
         self.max_segment_size = parse_file_size(self.config.get('repository', 'max_segment_size'))
         self.max_segment_size = parse_file_size(self.config.get('repository', 'max_segment_size'))