diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-23 17:48:56 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-23 17:48:56 +0000 |
commit | abfb13ca95e36c15f9b5041aba3139ddc6d39650 (patch) | |
tree | e495f7b33c51911af6c786a11ff11970349d8cff /obnamlib/plugins/fuse_plugin.py | |
parent | 1dad63b29f0e85ea51d80fc4719239caf56cead8 (diff) | |
download | obnam-abfb13ca95e36c15f9b5041aba3139ddc6d39650.tar.gz |
Break huge if/else
The then-branch ends in a return, so the else branch doesn't need to
be part of the if/else, and can just be de-indented, for a little
extra clarity.
Diffstat (limited to 'obnamlib/plugins/fuse_plugin.py')
-rw-r--r-- | obnamlib/plugins/fuse_plugin.py | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/obnamlib/plugins/fuse_plugin.py b/obnamlib/plugins/fuse_plugin.py index dc1ebd89..38ff85fb 100644 --- a/obnamlib/plugins/fuse_plugin.py +++ b/obnamlib/plugins/fuse_plugin.py @@ -150,56 +150,56 @@ class ObnamFuseFile(object): 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]) + + 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) + # 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) |