From 38f293a9135fe99af5aa7ad4b3309fa8a5177925 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Sat, 3 Jan 2009 14:02:45 -0700 Subject: [PATCH] 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 "" --- src/allmydata/storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) -- 2.45.2