فهرست منبع

creating a new segment: use "xb" mode, fixes #2099

"ab" seems to make no sense here (if there is already a (crap, but non-empty) segment file,
we would write a MAGIC right into the middle of the resulting file) and cause #2099.
Thomas Waldmann 8 سال پیش
والد
کامیت
6996fa6dc0
1فایلهای تغییر یافته به همراه2 افزوده شده و 1 حذف شده
  1. 2 1
      borg/repository.py

+ 2 - 1
borg/repository.py

@@ -670,7 +670,8 @@ class LoggedIO:
                 if not os.path.exists(dirname):
                     os.mkdir(dirname)
                     sync_dir(os.path.join(self.path, 'data'))
-            self._write_fd = open(self.segment_filename(self.segment), 'ab')
+            # play safe: fail if file exists (do not overwrite existing contents, do not append)
+            self._write_fd = open(self.segment_filename(self.segment), 'xb')
             self._write_fd.write(MAGIC)
             self.offset = MAGIC_LEN
         return self._write_fd