]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
immutable: when storage server reads from immutable share, don't try to read past...
authorZooko O'Whielacronx <zooko@zooko.com>
Sat, 3 Jan 2009 20:22:22 +0000 (13:22 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Sat, 3 Jan 2009 20:22:22 +0000 (13:22 -0700)
src/allmydata/storage.py

index d3ae86759641dc61f7362919f38269533787172d..1bed937d2204ac077baf9af54b41e16e0b343bd7 100644 (file)
@@ -135,9 +135,17 @@ class ShareFile:
 
     def read_share_data(self, offset, length):
         precondition(offset >= 0)
+        # 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')
-        f.seek(self._data_offset+offset)
-        return f.read(length)
+        seekpos = self._data_offset+offset
+        fsize = os.path.getsize(self.home)
+        actuallength = min(0, length, fsize-seekpos)
+        if actuallength == 0:
+            return ""
+        f.seek(seekpos)
+        return f.read(actuallength)
 
     def write_share_data(self, offset, data):
         length = len(data)