changeset 1317:76a76def8687

remove most chmod calls, use 1 os.umask() call in request module instead (port from 1.5)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 18 Aug 2006 21:20:15 +0200
parents c4f6af5ee295
children 760002b5ffa3
files MoinMoin/PageEditor.py MoinMoin/action/AttachFile.py MoinMoin/action/PackagePages.py MoinMoin/caching.py MoinMoin/logfile/__init__.py MoinMoin/packages.py MoinMoin/request/__init__.py MoinMoin/user.py MoinMoin/util/filesys.py MoinMoin/wikiutil.py MoinMoin/xmlrpc/__init__.py docs/CHANGES
diffstat 12 files changed, 20 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/PageEditor.py	Fri Aug 18 21:20:15 2006 +0200
@@ -831,14 +831,11 @@
         
         if not os.path.exists(pagedir): # new page, create and init pagedir
             os.mkdir(pagedir)
-            os.chmod(pagedir, 0777 & config.umask)
         if not os.path.exists(revdir):        
             os.mkdir(revdir)
-            os.chmod(revdir, 0777 & config.umask)
             f = open(cfn, 'w')
             f.write('%08d\n' % 0)
             f.close()
-            os.chmod(cfn, 0666 & config.umask)
             
         got_lock = False
         retry = 0
@@ -878,7 +875,6 @@
                 # Write the file using text/* mime type
                 f.write(self.encodeTextMimeType(text))
                 f.close()
-                os.chmod(pagefile, 0666 & config.umask)
                 mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
                 # set in-memory content
                 self.set_raw_body(text)
--- a/MoinMoin/action/AttachFile.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/action/AttachFile.py	Fri Aug 18 21:20:15 2006 +0200
@@ -189,7 +189,6 @@
             stream.write(filecontent)
         finally:
             stream.close()
-        os.chmod(fpath, 0666 & config.umask)
 
         _addLogEntry(request, 'ATTNEW', pagename, target)
 
@@ -625,7 +624,6 @@
             stream.write(filecontent)
         finally:
             stream.close()
-        os.chmod(savepath, 0666 & config.umask)
 
     # touch attachment directory to invalidate cache if new map is saved
     if ext == '.map':
@@ -760,7 +758,6 @@
                                     os.unlink(new_file)
                                 else:
                                     valid_name = True
-                                    os.chmod(new_file, 0666 & config.umask)
                                     _addLogEntry(request, 'ATTNEW', pagename, finalname)
 
                 if valid_name:
--- a/MoinMoin/action/PackagePages.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/action/PackagePages.py	Fri Aug 18 21:20:15 2006 +0200
@@ -113,8 +113,6 @@
         zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
         zf.close()
 
-        os.chmod(fpath, 0666 & config.umask)
-
         _addLogEntry(self.request, 'ATTNEW', self.pagename, target)
 
         raise ActionError(_("Created the package %s containing the pages %s.") % (wikiutil.escape(target), wikiutil.escape(pagelist)))
--- a/MoinMoin/caching.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/caching.py	Fri Aug 18 21:20:15 2006 +0200
@@ -99,10 +99,6 @@
                 shutil.copyfile(filename, tmpfname)
                 # this is either atomic or happening with real locks set:
                 filesys.rename(tmpfname, fname)
-                try:
-                    os.chmod(self._filename(), 0666 & config.umask)
-                except OSError:
-                    pass
             finally:
                 if self.locking:
                     self.wlock.release()
@@ -124,10 +120,6 @@
                 f.close()
                 # this is either atomic or happening with real locks set:
                 filesys.rename(tmpfname, fname)
-                try:
-                    os.chmod(fname, 0666 & config.umask)
-                except OSError:
-                    pass
             finally:
                 if self.locking:
                     self.wlock.release()
--- a/MoinMoin/logfile/__init__.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/logfile/__init__.py	Fri Aug 18 21:20:15 2006 +0200
@@ -139,11 +139,6 @@
             return self._input
         elif name == "_output":
             self._output = codecs.open(self.__filename, 'a', config.charset)
-            try:
-                os.chmod(self.__filename, 0666 & config.umask)
-            except OSError:
-                # TODO: should not ignore errors like this!
-                pass
             return self._output
         else:
             raise AttributeError(name)
--- a/MoinMoin/packages.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/packages.py	Fri Aug 18 21:20:15 2006 +0200
@@ -255,16 +255,13 @@
         revstr = '%08d' % 1
         if not os.path.exists(revdir):
             os.mkdir(revdir)
-            os.chmod(revdir, 0777 & config.umask)
 
         currentf = open(cfn, 'w')
         currentf.write(revstr + "\n")
         currentf.close()
-        os.chmod(cfn, 0666 & config.umask)
 
         pagefile = os.path.join(revdir, revstr)
         self._extractToFile(filename, pagefile)
-        os.chmod(pagefile, 0666 & config.umask)
 
         # Clear caches
         try:
--- a/MoinMoin/request/__init__.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/request/__init__.py	Fri Aug 18 21:20:15 2006 +0200
@@ -18,6 +18,13 @@
 from MoinMoin import config, wikiutil, user, caching, error
 from MoinMoin.util import IsWin9x
 
+# umask setting --------------------------------------------------------
+# We do this once per Python process, when request is imported:
+try:
+    # we need to use a bitwise inverted value of config.umask
+    os.umask(0777 ^ config.umask)
+except: # we are on win32
+    pass
 
 # Exceptions -----------------------------------------------------------
 
--- a/MoinMoin/user.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/user.py	Fri Aug 18 21:20:15 2006 +0200
@@ -525,11 +525,6 @@
                 data.write(line)
         data.close()
 
-        try:
-            os.chmod(self.__filename(), 0666 & config.umask)
-        except OSError:
-            pass
-
         if not self.disabled:
             self.valid = 1
 
@@ -580,10 +575,6 @@
             bmfile = open(bm_fn, "w")
             bmfile.write(str(tm)+"\n")
             bmfile.close()
-            try:
-                os.chmod(bm_fn, 0666 & config.umask)
-            except OSError:
-                pass
 
     def getBookmark(self):
         """ Get bookmark timestamp.
@@ -869,12 +860,6 @@
                 file.write(data)
             finally:
                 file.close()
-
-            try:
-                os.chmod(path, 0666 & config.umask)
-            except OSError, err:
-                self._request.log("Can't change mode of trail file: %s" %
-                                  str(err))
         except (IOError, OSError), err:
             self._request.log("Can't save trail file: %s" % str(err))
 
--- a/MoinMoin/util/filesys.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/util/filesys.py	Fri Aug 18 21:20:15 2006 +0200
@@ -15,8 +15,12 @@
 #############################################################################
 
 def chmod(name, mode, catchexception=True):
+    """ change mode of some file/dir on platforms that support it.
+        usually you don't need this because we use os.umask() when importing
+        request.py
+    """
     try:
-        return os.chmod(name, mode)
+        os.chmod(name, mode)
     except OSError:
         if not catchexception:
             raise
@@ -31,6 +35,10 @@
     This is modified version of the os.makedirs from Python 2.4. We add
     explicit chmod call after the mkdir call. Fixes some practical
     permission problems on Linux.
+
+    TODO: we use os.umask() now so we usually don't need explicit chmod any
+          more. Check all callers os makedirs/makeDirs and also py2.3+
+          stdlib implementation and maybe remove this function here.
     """
     head, tail = os.path.split(name)
     if not tail:
@@ -86,7 +94,7 @@
             st = os.stat(src)
             mode = S_IMODE(st[ST_MODE])
             if hasattr(os, 'chmod'):
-                os.chmod(dst, mode)
+                os.chmod(dst, mode) # KEEP THIS ONE!
         #else: pass # we are on Win9x,ME - no chmod here
     else:
         shutil.copystat(src, dst)
--- a/MoinMoin/wikiutil.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/wikiutil.py	Fri Aug 18 21:20:15 2006 +0200
@@ -461,7 +461,6 @@
         metafile = codecs.open(self.metafilename, "w", "utf-8")
         metafile.write(meta)
         metafile.close()
-        filesys.chmod(self.metafilename, 0666 & config.umask)
         self.dirty = False
 
     def sync(self, mtime_usecs=None):
--- a/MoinMoin/xmlrpc/__init__.py	Thu Aug 17 19:58:52 2006 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Fri Aug 18 21:20:15 2006 +0200
@@ -822,7 +822,6 @@
         if os.path.exists(filename) and not os.path.isfile(filename):
             return self.noSuchPageFault()
         open(filename, 'wb+').write(data.data)
-        os.chmod(filename, 0666 & config.umask)
         AttachFile._addLogEntry(self.request, 'ATTNEW', pagename, filename)
         return xmlrpclib.Boolean(1)
 
--- a/docs/CHANGES	Thu Aug 17 19:58:52 2006 +0200
+++ b/docs/CHANGES	Fri Aug 18 21:20:15 2006 +0200
@@ -228,6 +228,9 @@
      * the count of created threads is limited now (default: 5), you can use 1
        to use non-threaded operation.
      * configurable socket.listen() backlog (default: 5)
+  * tuning:
+    * more efficient locking code on POSIX platforms, we do much less I/O there now
+    * removed most chmod calls in favour of a single os.umask call
   
 Version 1.5.4:
     HINT: read docs/README.migration.