diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-03-18 08:18:19 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-03-18 08:27:24 +0000 |
commit | b585b92b940d12af4d9ddabb1999b6202c3aa72c (patch) | |
tree | 0bba2c9d3d98e255a41ab79db75ab652131a3370 /obnamlib/plugins/fuse_plugin.py | |
parent | e1556613f870e5ad173b6a2348671ae8fafa1561 (diff) | |
download | obnam-b585b92b940d12af4d9ddabb1999b6202c3aa72c.tar.gz |
Bug fix: change FUSE read to read right amount of data
The actual bug was that when we extracted data from the chunk we were
processing at the time, we used "data[start:n]", where n is the number
of bytes we wanted to extract from this chunk. This is clearly wrong:
the slice end is an offset, not a length to be added to the start.
Thus, "data[start:start+n]" is the fix.
In addition, a small performance silliness is removed by fixing the
check for whether we should be extracting data from a chunk: if the
chunk ends at the start of the offset in the file from where data
should be returned, it should clearly not be considered.
Clarify code a bit as well, which was useful for me to understand
what's going on.
Diffstat (limited to 'obnamlib/plugins/fuse_plugin.py')
-rw-r--r-- | obnamlib/plugins/fuse_plugin.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/obnamlib/plugins/fuse_plugin.py b/obnamlib/plugins/fuse_plugin.py index 11746b86..b65e084a 100644 --- a/obnamlib/plugins/fuse_plugin.py +++ b/obnamlib/plugins/fuse_plugin.py @@ -163,20 +163,21 @@ class ObnamFuseFile(object): for chunkid in chunkids: if chunkid in size_cache: + # Don't read the contents of the chunk until later, + # in case it can be skipped completely. contents = None - size = size_cache[chunkid] else: contents = self.fuse_fs.obnam.repo.get_chunk_content(chunkid) - size = len(contents) - size_cache[chunkid] = size + size_cache[chunkid] = len(contents) + size = size_cache[chunkid] - if chunk_pos_in_file + size >= offset: + if chunk_pos_in_file + size > offset: start = offset - chunk_pos_in_file n = length - output_length if contents is None: contents = self.fuse_fs.obnam.repo.get_chunk_content( chunkid) - data = contents[start : n] + data = contents[start : start+n] output.append(data) output_length += len(data) assert output_length <= length |