From: Zooko O'Whielacronx Date: Sat, 3 Jan 2009 21:02:45 +0000 (-0700) Subject: immutable: fix think-o in previous patch which caused all reads to return "", and... X-Git-Url: https://git.rkrishnan.org/somewhere?a=commitdiff_plain;h=38f293a9135fe99af5aa7ad4b3309fa8a5177925;p=tahoe-lafs%2Ftahoe-lafs.git immutable: fix think-o in previous patch which caused all reads to return "", and also optimize by not opening the file when the answer is going to be "" --- diff --git a/src/allmydata/storage.py b/src/allmydata/storage.py index 1bed937d..74eeaa84 100644 --- a/src/allmydata/storage.py +++ b/src/allmydata/storage.py @@ -138,12 +138,12 @@ class ShareFile: # reads beyond the end of the data are truncated. Reads that start beyond the end of the # data return an empty string. # I wonder why Python doesn't do the following computation for me? - f = open(self.home, 'rb') seekpos = self._data_offset+offset fsize = os.path.getsize(self.home) - actuallength = min(0, length, fsize-seekpos) + actuallength = max(0, min(length, fsize-seekpos)) if actuallength == 0: return "" + f = open(self.home, 'rb') f.seek(seekpos) return f.read(actuallength)