changeset 1801:3369445b4aa8

move the dircache stuff to MoinMoin.util.filesys and disable it on win32
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 23 Feb 2007 23:08:41 +0100
parents e8a309cad6b7
children 0eca596ce903
files MoinMoin/Page.py MoinMoin/_tests/test_user.py MoinMoin/request/__init__.py MoinMoin/user.py MoinMoin/util/filesys.py
diffstat 5 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Fri Feb 23 22:04:30 2007 +0100
+++ b/MoinMoin/Page.py	Fri Feb 23 23:08:41 2007 +0100
@@ -13,6 +13,7 @@
 
 from MoinMoin import config, caching, user, util, wikiutil
 from MoinMoin.logfile import eventlog
+from MoinMoin.util import filesys
 
 def is_cache_exception(e):
     args = e.args
@@ -1338,12 +1339,11 @@
         @rtype: list of ints
         @return: page revisions
         """
-        import dircache
         revisions = []
         if self.page_name:
             rev_dir = self.getPagePath('revisions', check_create=0)
             if os.path.isdir(rev_dir):
-                for rev in dircache.listdir(rev_dir):
+                for rev in filesys.dclistdir(rev_dir):
                     try:
                         revint = int(rev)
                         revisions.append(revint)
@@ -1778,10 +1778,8 @@
         @rtype: dict
         @return: dict of page names using file system encoding
         """
-        import dircache
-
         pages = {}
-        for name in dircache.listdir(path):
+        for name in filesys.dclistdir(path):
             # Filter non-pages in quoted wiki names
             # List all pages in pages directory - assume flat namespace.
             # We exclude everything starting with '.' to get rid of . and ..
--- a/MoinMoin/_tests/test_user.py	Fri Feb 23 22:04:30 2007 +0100
+++ b/MoinMoin/_tests/test_user.py	Fri Feb 23 23:08:41 2007 +0100
@@ -6,11 +6,11 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest, os, dircache
+import unittest, os
 
 from MoinMoin._tests import TestConfig, TestSkipped
 from MoinMoin import user, caching
-
+from MoinMoin.util import filesys
 
 class EncodePasswordTestCase(unittest.TestCase):
     """user: encode passwords tests"""
@@ -47,12 +47,8 @@
         self.request.saved_cookie = ''
         self.request.user = user.User(self.request)
 
-        # Prevent user list caching - we create and delete users too
-        # fast for that.
-        try:
-            del dircache.cache[self.request.cfg.user_dir]
-        except KeyError:
-            pass
+        # Prevent user list caching - we create and delete users too fast for that.
+        filesys.dcdisable()
 
     def tearDown(self):
         """ Run after each test
@@ -76,12 +72,8 @@
         caching.CacheEntry(self.request, 'user', 'name2id', scope='wiki').remove()
         del self.request.cfg.cache.name2id
 
-        # Prevent user list caching - we create and delete users too
-        # fast for that.
-        try:
-            del dircache.cache[self.request.cfg.user_dir]
-        except KeyError:
-            pass
+        # Prevent user list caching - we create and delete users too fast for that.
+        filesys.dcdisable()
 
     def testAsciiPassword(self):
         """ user: login with ascii password """
--- a/MoinMoin/request/__init__.py	Fri Feb 23 22:04:30 2007 +0100
+++ b/MoinMoin/request/__init__.py	Fri Feb 23 23:08:41 2007 +0100
@@ -152,11 +152,6 @@
         self.page = None
         self._dicts = None
 
-        # Fix dircaching problems on Windows 9x
-        if IsWin9x():
-            import dircache
-            dircache.reset()
-
         # Check for dumb proxy requests
         # TODO relying on request_uri will not work on all servers, especially
         # not on external non-Apache servers
--- a/MoinMoin/user.py	Fri Feb 23 22:04:30 2007 +0100
+++ b/MoinMoin/user.py	Fri Feb 23 23:08:41 2007 +0100
@@ -12,7 +12,7 @@
 import os, time, sha, codecs
 
 from MoinMoin import config, caching, wikiutil, i18n
-from MoinMoin.util import timefuncs
+from MoinMoin.util import timefuncs, filesys
 
 
 def getUserList(request):
@@ -22,9 +22,9 @@
     @rtype: list
     @return: all user IDs
     """
-    import re, dircache
+    import re
     user_re = re.compile(r'^\d+\.\d+(\.\d+)?$')
-    files = dircache.listdir(request.cfg.user_dir)
+    files = filesys.dclistdir(request.cfg.user_dir)
     userlist = [f for f in files if user_re.match(f)]
     return userlist
 
--- a/MoinMoin/util/filesys.py	Fri Feb 23 22:04:30 2007 +0100
+++ b/MoinMoin/util/filesys.py	Fri Feb 23 23:08:41 2007 +0100
@@ -130,3 +130,22 @@
     def realPathCase(path):
         return None
 
+# dircache stuff seems to be broken on win32 (at least for FAT32, maybe NTFS)
+DCENABLED = 1 # set to 0 to disable dirchache usage
+def dcdisable():
+    global DCENABLED
+    DCENABLED = 0
+
+import dircache
+
+def dclistdir(path):
+    if sys.platform == 'win32' or not DCENABLED:
+        return os.listdir(path)
+    else:
+        return dircache.listdir(path)
+        
+def dcreset():
+    if sys.platform == 'win32' or not DCENABLED:
+        return
+    else:
+        return dircache.reset()