server/sources/storages.py
branchstable
changeset 5210 1c635a91e403
parent 5183 8d66003351f8
child 5218 aebd00a2d316
--- a/server/sources/storages.py	Fri Apr 09 15:01:14 2010 +0000
+++ b/server/sources/storages.py	Fri Apr 09 15:01:25 2010 +0000
@@ -85,9 +85,16 @@
 
     def entity_updated(self, entity, attr):
         """an entity using this storage for attr has been updatded"""
-        binary = entity.pop(attr)
-        fpath = self.current_fs_path(entity, attr)
-        UpdateFileOp(entity._cw, filepath=fpath, filedata=binary.getvalue())
+        if entity._cw.transaction_data.get('fs_importing'):
+            oldpath = self.current_fs_path(entity, attr)
+            fpath = entity[attr].getvalue()
+            if oldpath != fpath:
+                DeleteFileOp(entity._cw, filepath=oldpath)
+            binary = Binary(file(fpath).read())
+        else:
+            binary = entity.pop(attr)
+            fpath = self.current_fs_path(entity, attr)
+            UpdateFileOp(entity._cw, filepath=fpath, filedata=binary.getvalue())
         return binary
 
     def entity_deleted(self, entity, attr):