server/sources/storages.py
branchstable
changeset 5183 8d66003351f8
parent 5131 88b5ca8da928
child 5218 aebd00a2d316
--- a/server/sources/storages.py	Thu Apr 08 10:00:22 2010 +0200
+++ b/server/sources/storages.py	Thu Apr 08 09:59:59 2010 +0200
@@ -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):