Commit a6ed41fb by devttys0

Fixed hexdiff offset bug; fixed potential additional bugs in BlockFile length/offset calculations.

parent 4ddad90a
......@@ -153,9 +153,21 @@ class BlockFile(io.FileIO):
else:
self.offset = offset
if length:
if self.offset < 0:
self.offset = 0
elif self.offset > self.size:
self.offset = self.size
if offset < 0:
self.length = offset * -1
elif length:
self.length = length
else:
self.length = self.size - offset
if self.length < 0:
self.length = 0
elif self.length > self.size:
self.length = self.size
io.FileIO.__init__(self, fname, mode)
......@@ -167,7 +179,7 @@ class BlockFile(io.FileIO):
self._name = fname
self.seek(self.offset)
def write(self, data):
'''
Writes data to the opened file.
......
......@@ -101,6 +101,10 @@ class HexDiff(object):
data = {}
delim = '/'
# If negative offset, then we're going that far back from the end of the file
if offset < 0:
size = offset * -1
if show_first_only:
self._header([files[0]], block)
else:
......@@ -122,9 +126,16 @@ class HexDiff(object):
while total < size:
i = 0
files_finished = 0
for fp in fps:
(ddata, dlen) = fp.read_block()
data[fp.name] = ddata
if not ddata or dlen == 0:
files_finished += 1
if files_finished == len(fps):
break
while i < read_block_size and (total+i) < size:
diff_same = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment