diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-23 17:48:06 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-23 17:48:06 +0000 |
commit | 1dad63b29f0e85ea51d80fc4719239caf56cead8 (patch) | |
tree | 531e2bc2c5b7dff1ae80e17a5850e765ae38a65c /obnamlib/plugins/fuse_plugin.py | |
parent | 46327995de5058b95f93b86afbfd88e5d45f1413 (diff) | |
download | obnam-1dad63b29f0e85ea51d80fc4719239caf56cead8.tar.gz |
Remove unnecessary try/except
It was only used for logging, and that's handled top-level just fine.
Having it here only obfuscates the code.
Diffstat (limited to 'obnamlib/plugins/fuse_plugin.py')
-rw-r--r-- | obnamlib/plugins/fuse_plugin.py | 131 |
1 files changed, 62 insertions, 69 deletions
diff --git a/obnamlib/plugins/fuse_plugin.py b/obnamlib/plugins/fuse_plugin.py index 262340cf..dc1ebd89 100644 --- a/obnamlib/plugins/fuse_plugin.py +++ b/obnamlib/plugins/fuse_plugin.py @@ -133,80 +133,73 @@ class ObnamFuseFile(object): if length == 0 or offset >= self.metadata.st_size: return '' - try: + repo = self.fs.obnam.repo - repo = self.fs.obnam.repo - gen, repopath = self.fs.get_gen_path(self.path) + gen, repopath = self.fs.get_gen_path(self.path) - # if stored inside B-tree - contents = repo.get_file_data(gen, repopath) - if contents is not None: - return contents[offset:offset+length] + # if stored inside B-tree + contents = repo.get_file_data(gen, repopath) + if contents is not None: + return contents[offset:offset+length] - # stored in chunks - if not self.chunkids: - self.chunkids = repo.get_file_chunks(gen, repopath) + # stored in chunks + if not self.chunkids: + self.chunkids = repo.get_file_chunks(gen, repopath) - if len(self.chunkids) == 1: - if not self.lastdata: - self.lastdata = repo.get_chunk(self.chunkids[0]) - return self.lastdata[offset:offset+length] - else: - chunkdata = None - if not self.chunksize: - # take the cached value as the first guess for chunksize - self.chunksize = self.fs.sizecache.get(gen, self.fs.chunksize) - blocknum = offset/self.chunksize - blockoffs = offset - blocknum*self.chunksize - - # read a chunk if guessed blocknum and chunksize make sense - if blocknum < len(self.chunkids): - chunkdata = repo.get_chunk(self.chunkids[blocknum]) - else: - chunkdata = '' - - # check if chunkdata is of expected length - validate = min(self.chunksize, self.metadata.st_size - blocknum*self.chunksize) - if validate != len(chunkdata): - if blocknum < len(self.chunkids)-1: - # the length of all but last chunks is chunksize - self.chunksize = len(chunkdata) - else: - # guessing failed, get the length of the first chunk - self.chunksize = len(repo.get_chunk(self.chunkids[0])) - chunkdata = None - - # save correct chunksize - self.fs.sizecache[gen] = self.chunksize - - if not chunkdata: - blocknum = offset/self.chunksize - blockoffs = offset - blocknum*self.chunksize - if self.lastblock == blocknum: - chunkdata = self.lastdata - else: - chunkdata = repo.get_chunk(self.chunkids[blocknum]) - - output = [] - while True: - output.append(chunkdata[blockoffs:blockoffs+length]) - readlength = len(chunkdata) - blockoffs - if length > readlength and blocknum < len(self.chunkids)-1: - length -= readlength - blocknum += 1 - blockoffs = 0 - chunkdata = repo.get_chunk(self.chunkids[blocknum]) + if len(self.chunkids) == 1: + if not self.lastdata: + self.lastdata = repo.get_chunk(self.chunkids[0]) + return self.lastdata[offset:offset+length] + else: + chunkdata = None + if not self.chunksize: + # take the cached value as the first guess for chunksize + self.chunksize = self.fs.sizecache.get(gen, self.fs.chunksize) + blocknum = offset/self.chunksize + blockoffs = offset - blocknum*self.chunksize + + # read a chunk if guessed blocknum and chunksize make sense + if blocknum < len(self.chunkids): + chunkdata = repo.get_chunk(self.chunkids[blocknum]) + else: + chunkdata = '' + + # check if chunkdata is of expected length + validate = min(self.chunksize, self.metadata.st_size - blocknum*self.chunksize) + if validate != len(chunkdata): + if blocknum < len(self.chunkids)-1: + # the length of all but last chunks is chunksize + self.chunksize = len(chunkdata) else: - self.lastblock = blocknum - self.lastdata = chunkdata - break - return ''.join(output) - except (OSError, IOError), e: - tracing.trace('expected exception: %r', e) - raise - except: - logging.exception('Unexpected exception') - raise + # guessing failed, get the length of the first chunk + self.chunksize = len(repo.get_chunk(self.chunkids[0])) + chunkdata = None + + # save correct chunksize + self.fs.sizecache[gen] = self.chunksize + + if not chunkdata: + blocknum = offset/self.chunksize + blockoffs = offset - blocknum*self.chunksize + if self.lastblock == blocknum: + chunkdata = self.lastdata + else: + chunkdata = repo.get_chunk(self.chunkids[blocknum]) + + output = [] + while True: + output.append(chunkdata[blockoffs:blockoffs+length]) + readlength = len(chunkdata) - blockoffs + if length > readlength and blocknum < len(self.chunkids)-1: + length -= readlength + blocknum += 1 + blockoffs = 0 + chunkdata = repo.get_chunk(self.chunkids[blocknum]) + else: + self.lastblock = blocknum + self.lastdata = chunkdata + break + return ''.join(output) def release(self, flags): tracing.trace('flags=%r', flags) |