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.
This commit is contained in:
Thomas Waldmann 2017-01-23 20:47:33 +01:00
parent ca0c1dab11
commit 6996fa6dc0

View file

@ -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