mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 13:45:31 +00:00
Consider segment incomplete if segment file is empty or too small
This fixes an IOError that could be raised when trying to seek() to a negative file offset, because (for any reason) a segment file was empty (or too small).
This commit is contained in:
parent
e9fd2bc5e8
commit
c93363946b
1 changed files with 8 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
from configparser import RawConfigParser
|
||||
from binascii import hexlify
|
||||
import errno
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
@ -314,7 +315,13 @@ def cleanup(self):
|
|||
|
||||
def is_complete_segment(self, filename):
|
||||
with open(filename, 'rb') as fd:
|
||||
fd.seek(-self.header_fmt.size, 2)
|
||||
try:
|
||||
fd.seek(-self.header_fmt.size, os.SEEK_END)
|
||||
except Exception as e:
|
||||
# return False if segment file is empty or too small
|
||||
if e.errno == errno.EINVAL:
|
||||
return False
|
||||
raise e
|
||||
return fd.read(self.header_fmt.size) == self.COMMIT
|
||||
|
||||
def segment_filename(self, segment):
|
||||
|
|
Loading…
Reference in a new issue