From c93363946b4da1fe3c832483ab832239415d3c31 Mon Sep 17 00:00:00 2001 From: Petros Moisiadis Date: Mon, 30 Dec 2013 17:21:47 +0200 Subject: [PATCH] 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). --- attic/repository.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/attic/repository.py b/attic/repository.py index 0f9f4cbe8..f9e0c2deb 100644 --- a/attic/repository.py +++ b/attic/repository.py @@ -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):