1- # $Id: back_metakit.py,v 1.70.2.4 2004-06-24 07:14:47 richard Exp $
1+ # $Id: back_metakit.py,v 1.70.2.5 2004-06-24 09:56:49 richard Exp $
22'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44Known Current Bugs:
@@ -1887,21 +1887,25 @@ def create(self, **propvalues):
18871887
18881888 # figure a filename
18891889 nm = self .gen_filename (newid )
1890+
1891+ # make sure we don't register the rename action more than once
1892+ if not os .path .exists (nm + '.tmp' ):
1893+ # register commit and rollback actions
1894+ def commit (fnm = nm ):
1895+ os .rename (fnm + '.tmp' , fnm )
1896+ self .commitaction (commit )
1897+ def undo (fnm = nm ):
1898+ os .remove (fnm + '.tmp' )
1899+ self .rollbackaction (undo )
1900+
1901+ # save the tempfile
18901902 f = open (nm + '.tmp' , 'wb' )
18911903 f .write (content )
18921904 f .close ()
18931905
18941906 mimetype = propvalues .get ('type' , self .default_mime_type )
18951907 self .db .indexer .add_text ((self .classname , newid , 'content' ), content ,
18961908 mimetype )
1897-
1898- # register commit and rollback actions
1899- def commit (fnm = nm ):
1900- os .rename (fnm + '.tmp' , fnm )
1901- self .commitaction (commit )
1902- def undo (fnm = nm ):
1903- os .remove (fnm + '.tmp' )
1904- self .rollbackaction (undo )
19051909 return newid
19061910
19071911 def set (self , itemid , ** propvalues ):
@@ -1918,23 +1922,27 @@ def set(self, itemid, **propvalues):
19181922 # figure a filename
19191923 if content is not None :
19201924 nm = self .gen_filename (itemid )
1925+
1926+ # make sure we don't register the rename action more than once
1927+ if not os .path .exists (nm + '.tmp' ):
1928+ # register commit and rollback actions
1929+ def commit (fnm = nm ):
1930+ if os .path .exists (fnm ):
1931+ os .remove (fnm )
1932+ os .rename (fnm + '.tmp' , fnm )
1933+ self .commitaction (commit )
1934+ def undo (fnm = nm ):
1935+ os .remove (fnm + '.tmp' )
1936+ self .rollbackaction (undo )
1937+
19211938 f = open (nm + '.tmp' , 'wb' )
19221939 f .write (content )
19231940 f .close ()
1941+
19241942 mimetype = propvalues .get ('type' , self .default_mime_type )
19251943 self .db .indexer .add_text ((self .classname , itemid , 'content' ),
19261944 content , mimetype )
19271945
1928- # register commit and rollback actions
1929- def commit (fnm = nm ):
1930- if os .path .exists (fnm ):
1931- os .remove (fnm )
1932- os .rename (fnm + '.tmp' , fnm )
1933- self .commitaction (commit )
1934- def undo (fnm = nm ):
1935- os .remove (fnm + '.tmp' )
1936- self .rollbackaction (undo )
1937-
19381946 self .fireReactors ('set' , oldnode , propvalues )
19391947
19401948 def index (self , nodeid ):
0 commit comments