Commit 3c34e366 authored by Martijn Pieters's avatar Martijn Pieters

Fix for Collector issue #671: PData chains are of equal length, except the

*first* entry (and not the last one as assumed before).

- Adjust test to create a big file that will have a Pdata entry of smaller
  size

- Fix pdata_map lookups with first-entry-size in mind.
parent 9996361e
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Image object""" """Image object"""
__version__='$Revision: 1.142 $'[11:-2] __version__='$Revision: 1.143 $'[11:-2]
import Globals, struct import Globals, struct
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
...@@ -323,7 +323,13 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -323,7 +323,13 @@ class File(Persistent, Implicit, PropertyManager,
# calculations allow us to fast-forward through the # calculations allow us to fast-forward through the
# Pdata chain without a lot of dereferencing if we # Pdata chain without a lot of dereferencing if we
# did the work already. # did the work already.
closest_pos = start - (start % (1<<16)) first_size = len(pdata_map[0].data)
if start < first_size:
closest_pos = 0
else:
closest_pos = (
((start - first_size) >> 16 << 16) +
first_size)
pos = min(closest_pos, max(pdata_map.keys())) pos = min(closest_pos, max(pdata_map.keys()))
data = pdata_map[pos] data = pdata_map[pos]
......
...@@ -33,7 +33,8 @@ def makeConnection(): ...@@ -33,7 +33,8 @@ def makeConnection():
def createBigFile(): def createBigFile():
# Create a file that is several 1<<16 blocks of data big, to force the # Create a file that is several 1<<16 blocks of data big, to force the
# use of chained Pdata objects. # use of chained Pdata objects.
size = (1<<16) * 5 # Make sure we create a file that isn't of x * 1<<16 length! Coll #671
size = (1<<16) * 5 + 12345
file = cStringIO.StringIO() file = cStringIO.StringIO()
def addLetter(x, add=file.write, l=string.letters, def addLetter(x, add=file.write, l=string.letters,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment