Commit 4b6ab743 authored by Jim Fulton's avatar Jim Fulton

Removed the unnecessary and unused version argument from storeBlob.

Added a temporaryDirectory method for getting a directory to use for
creating temporary files.
parent 6c2e5364
...@@ -61,6 +61,11 @@ class BlobStorage(SpecificationDecoratorBase): ...@@ -61,6 +61,11 @@ class BlobStorage(SpecificationDecoratorBase):
supportsUndo = supportsUndo() supportsUndo = supportsUndo()
self.__supportsUndo = supportsUndo self.__supportsUndo = supportsUndo
@non_overridable
def temporaryDirectory(self):
return self.fshelper.base_dir
@non_overridable @non_overridable
def __repr__(self): def __repr__(self):
normal_storage = getProxiedObject(self) normal_storage = getProxiedObject(self)
...@@ -114,13 +119,12 @@ class BlobStorage(SpecificationDecoratorBase): ...@@ -114,13 +119,12 @@ class BlobStorage(SpecificationDecoratorBase):
os.unlink(clean) os.unlink(clean)
@non_overridable @non_overridable
def loadBlob(self, oid, serial, version): def loadBlob(self, oid, serial):
"""Return the filename where the blob file can be found. """Return the filename where the blob file can be found.
""" """
filename = self.fshelper.getBlobFilename(oid, serial) filename = self.fshelper.getBlobFilename(oid, serial)
if not os.path.exists(filename): if not os.path.exists(filename):
raise POSKeyError, "Not an existing blob." return None
return filename return filename
@non_overridable @non_overridable
......
...@@ -60,11 +60,16 @@ class IBlobStorage(Interface): ...@@ -60,11 +60,16 @@ class IBlobStorage(Interface):
def storeBlob(oid, oldserial, data, blob, version, transaction): def storeBlob(oid, oldserial, data, blob, version, transaction):
"""Stores data that has a BLOB attached.""" """Stores data that has a BLOB attached."""
def loadBlob(oid, serial, version): def loadBlob(oid, serial):
"""Return the filename of the Blob data responding to this OID and """Return the filename of the Blob data for this OID and serial.
serial.
Returns a filename or None if no Blob data is connected with this OID. Returns a filename or None if no Blob data is connected with this OID.
Raises POSKeyError if the blobfile cannot be found. Raises POSKeyError if the blobfile cannot be found.
""" """
def temporaryDirectory():
"""Return a directory that should be used for uncommitted blob data.
If Blobs use this, then commits can be performed with a simple rename.
"""
...@@ -853,8 +853,7 @@ class Connection(ExportImport, object): ...@@ -853,8 +853,7 @@ class Connection(ExportImport, object):
providedBy = getattr(obj, '__providedBy__', None) providedBy = getattr(obj, '__providedBy__', None)
if providedBy is not None and IBlob in providedBy: if providedBy is not None and IBlob in providedBy:
obj._p_blob_uncommitted = None obj._p_blob_uncommitted = None
obj._p_blob_data = self._storage.loadBlob( obj._p_blob_data = self._storage.loadBlob(obj._p_oid, serial)
obj._p_oid, serial, self._version)
def _load_before_or_conflict(self, obj): def _load_before_or_conflict(self, obj):
"""Load non-current state for obj or raise ReadConflictError.""" """Load non-current state for obj or raise ReadConflictError."""
...@@ -1108,7 +1107,7 @@ class Connection(ExportImport, object): ...@@ -1108,7 +1107,7 @@ class Connection(ExportImport, object):
for oid in oids: for oid in oids:
data, serial = src.load(oid, src) data, serial = src.load(oid, src)
try: try:
blobfilename = src.loadBlob(oid, serial, self._version) blobfilename = src.loadBlob(oid, serial)
except POSKeyError: except POSKeyError:
s = self._storage.store(oid, serial, data, s = self._storage.store(oid, serial, data,
self._version, transaction) self._version, transaction)
...@@ -1250,7 +1249,7 @@ class TmpStore: ...@@ -1250,7 +1249,7 @@ class TmpStore:
targetname = self._getCleanFilename(oid, serial) targetname = self._getCleanFilename(oid, serial)
os.rename(blobfilename, targetname) os.rename(blobfilename, targetname)
def loadBlob(self, oid, serial, version): def loadBlob(self, oid, serial):
"""Return the filename where the blob file can be found. """Return the filename where the blob file can be found.
""" """
filename = self._getCleanFilename(oid, serial) filename = self._getCleanFilename(oid, serial)
......
...@@ -39,6 +39,7 @@ class ExportImport: ...@@ -39,6 +39,7 @@ class ExportImport:
done_oids = {} done_oids = {}
done=done_oids.has_key done=done_oids.has_key
load=self._storage.load load=self._storage.load
supports_blobs = IBlobStorage.providedBy(self._storage)
while oids: while oids:
oid = oids.pop(0) oid = oids.pop(0)
if oid in done_oids: if oid in done_oids:
...@@ -52,13 +53,14 @@ class ExportImport: ...@@ -52,13 +53,14 @@ class ExportImport:
else: else:
referencesf(p, oids) referencesf(p, oids)
f.writelines([oid, p64(len(p)), p]) f.writelines([oid, p64(len(p)), p])
# Blob support
if not IBlobStorage.providedBy(self._storage): if supports_blobs:
continue if 'Blob' not in p:
try: continue # filter out most non-blobs
blobfilename = self._storage.loadBlob(oid,
serial, self._version) blobfilename = self._storage.loadBlob(oid, serial)
except POSKeyError: # Looks like this is not a blob if blobfilename is None:
# This could be a non-blob or a blob with unsaved data.
continue continue
f.write(blob_begin_marker) f.write(blob_begin_marker)
......
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