diff roundup/backends/blobfiles.py @ 2906:a8808157f892

fix some bugs introduced in refactoring of blobfiles filename() unless in debug mode, keep a single persistent connection through a single web or mailgw request fix enabling of DEBUG logging in db_test_case (no cmdline switch yet)
author Richard Jones <richard@users.sourceforge.net>
date Fri, 12 Nov 2004 04:07:05 +0000
parents 09a4d6dd6dcb
children 4607f58a007b
line wrap: on
line diff
--- a/roundup/backends/blobfiles.py	Thu Nov 11 21:36:07 2004 +0000
+++ b/roundup/backends/blobfiles.py	Fri Nov 12 04:07:05 2004 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-#$Id: blobfiles.py,v 1.14 2004-11-11 06:04:59 richard Exp $
+#$Id: blobfiles.py,v 1.15 2004-11-12 04:07:05 richard Exp $
 '''This module exports file storage for roundup backends.
 Files are stored into a directory hierarchy.
 '''
@@ -37,7 +37,7 @@
 
 class FileStorage:
     """Store files in some directory structure"""
-    def filename(self, classname, nodeid, property=None):
+    def filename(self, classname, nodeid, property=None, create=False):
         '''Determine what the filename for the given node and optionally 
         property is.
 
@@ -55,7 +55,7 @@
         # have a separate subdir for every thousand messages
         subdir = str(int(nodeid) / 1000)
         filename  = os.path.join(self.dir, 'files', classname, subdir, name)
-        if os.path.exists(filename):
+        if create or os.path.exists(filename):
             return filename
 
         # try .tmp
@@ -82,7 +82,7 @@
            is being saved.
         '''
         # determine the name of the file to write to
-        name = self.filename(classname, nodeid, property)
+        name = self.filename(classname, nodeid, property, create=True)
 
         # make sure the file storage dir exists
         if not os.path.exists(os.path.dirname(name)):
@@ -90,6 +90,7 @@
 
         # save to a temp file
         name = name + '.tmp'
+
         # make sure we don't register the rename action more than once
         if not os.path.exists(name):
             # save off the rename action
@@ -121,13 +122,21 @@
         # determine the name of the file to write to
         name = self.filename(classname, nodeid, property)
 
+        # the file is currently ".tmp" - move it to its real name to commit
+        if name.endswith('.tmp'):
+            # creation
+            dstname = os.path.splitext(name)[0]
+        else:
+            # edit operation
+            dstname = name
+            name = name + '.tmp'
+
         # content is being updated (and some platforms, eg. win32, won't
         # let us rename over the top of the old file)
-        if os.path.exists(name):
-            os.remove(name)
+        if os.path.exists(dstname):
+            os.remove(dstname)
 
-        # the file is currently ".tmp" - move it to its real name to commit
-        os.rename(name+".tmp", name)
+        os.rename(name, dstname)
 
         # return the classname, nodeid so we reindex this content
         return (classname, nodeid)

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