1414# FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17- #
18- #$Id: blobfiles.py,v 1.19 2005-06-08 03:35:18 anthonybaxter Exp $
17+ #
18+ #$Id: blobfiles.py,v 1.20 2007-09-11 21:33:30 jpend Exp $
1919'''This module exports file storage for roundup backends.
2020Files are stored into a directory hierarchy.
2121'''
@@ -36,22 +36,25 @@ def files_in_dir(dir):
3636 return num_files
3737
3838class FileStorage :
39- """Store files in some directory structure"""
39+ def __init__ (self , umask ):
40+ self .umask = umask
41+
42+ """Store files in some directory structure"""
4043 def subdirFilename (self , classname , nodeid , property = None ):
4144 """Determine what the filename and subdir for nodeid + classname is."""
4245 if property :
4346 name = '%s%s.%s' % (classname , nodeid , property )
4447 else :
45- # roundupdb.FileClass never specified the property name, so don't
48+ # roundupdb.FileClass never specified the property name, so don't
4649 # include it
4750 name = '%s%s' % (classname , nodeid )
48-
51+
4952 # have a separate subdir for every thousand messages
5053 subdir = str (int (nodeid ) / 1000 )
5154 return os .path .join (subdir , name )
52-
55+
5356 def filename (self , classname , nodeid , property = None , create = 0 ):
54- '''Determine what the filename for the given node and optionally
57+ '''Determine what the filename for the given node and optionally
5558 property is.
5659
5760 Try a variety of different filenames - the file could be in the
@@ -101,6 +104,10 @@ def storefile(self, classname, nodeid, property, content):
101104 # save off the rename action
102105 self .transactions .append ((self .doStoreFile , (classname , nodeid ,
103106 property )))
107+ # always set umask before writing to make sure we have the proper one
108+ # in multi-tracker (i.e. multi-umask) or modpython scenarios
109+ # the umask may have changed since last we set it.
110+ os .umask (self .umask )
104111 open (name , 'wb' ).write (content )
105112
106113 def getfile (self , classname , nodeid , property ):
0 commit comments