From 6996fa6dc0ba1feb762e6ec3a012cad2c219cc21 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 23 Jan 2017 20:47:33 +0100 Subject: [PATCH] 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. --- borg/repository.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/borg/repository.py b/borg/repository.py index dd49b368b..058e894e3 100644 --- a/borg/repository.py +++ b/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