changeset 2501:f778acabf200 maint-0.7 0.7.5

fix for transaction fun in metakit FileClass
author Richard Jones <richard@users.sourceforge.net>
date Thu, 24 Jun 2004 09:56:49 +0000
parents 00f3eec8ef9a
children 3550ad56137a
files roundup/backends/back_metakit.py
diffstat 1 files changed, 27 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/backends/back_metakit.py	Thu Jun 24 07:59:56 2004 +0000
+++ b/roundup/backends/back_metakit.py	Thu Jun 24 09:56:49 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: back_metakit.py,v 1.70.2.4 2004-06-24 07:14:47 richard Exp $
+# $Id: back_metakit.py,v 1.70.2.5 2004-06-24 09:56:49 richard Exp $
 '''Metakit backend for Roundup, originally by Gordon McMillan.
 
 Known Current Bugs:
@@ -1887,6 +1887,18 @@
 
         # figure a filename
         nm = self.gen_filename(newid)
+
+        # make sure we don't register the rename action more than once
+        if not os.path.exists(nm + '.tmp'):
+            # register commit and rollback actions
+            def commit(fnm=nm):
+                os.rename(fnm + '.tmp', fnm)
+            self.commitaction(commit)
+            def undo(fnm=nm):
+                os.remove(fnm + '.tmp')
+            self.rollbackaction(undo)
+
+        # save the tempfile
         f = open(nm + '.tmp', 'wb')
         f.write(content)
         f.close()
@@ -1894,14 +1906,6 @@
         mimetype = propvalues.get('type', self.default_mime_type)
         self.db.indexer.add_text((self.classname, newid, 'content'), content,
             mimetype)
-
-        # register commit and rollback actions
-        def commit(fnm=nm):
-            os.rename(fnm + '.tmp', fnm)
-        self.commitaction(commit)
-        def undo(fnm=nm):
-            os.remove(fnm + '.tmp')
-        self.rollbackaction(undo)
         return newid
 
     def set(self, itemid, **propvalues):
@@ -1918,23 +1922,27 @@
         # figure a filename
         if content is not None:
             nm = self.gen_filename(itemid)
+
+            # make sure we don't register the rename action more than once
+            if not os.path.exists(nm + '.tmp'):
+                # register commit and rollback actions
+                def commit(fnm=nm):
+                    if os.path.exists(fnm):
+                        os.remove(fnm)
+                    os.rename(fnm + '.tmp', fnm)
+                self.commitaction(commit)
+                def undo(fnm=nm):
+                    os.remove(fnm + '.tmp')
+                self.rollbackaction(undo)
+
             f = open(nm + '.tmp', 'wb')
             f.write(content)
             f.close()
+
             mimetype = propvalues.get('type', self.default_mime_type)
             self.db.indexer.add_text((self.classname, itemid, 'content'),
                 content, mimetype)
 
-            # register commit and rollback actions
-            def commit(fnm=nm):
-                if os.path.exists(fnm):
-                    os.remove(fnm)
-                os.rename(fnm + '.tmp', fnm)
-            self.commitaction(commit)
-            def undo(fnm=nm):
-                os.remove(fnm + '.tmp')
-            self.rollbackaction(undo)
-
         self.fireReactors('set', oldnode, propvalues)
 
     def index(self, nodeid):

Roundup Issue Tracker: http://roundup-tracker.org/