[viewvc-dev] [PATCH] extend "forbidden" to support path patterns

Salvador Fandino <[email protected]>
Newsgroups gmane.comp.version-control.cvs.viewcvs.devel
Message-ID <[email protected]>
Currently, the vzauth.forbidden module only allows to specify first 
level packages, for instance:

   forbidden = foo, bar*

Specifying packages in subdirectories as:

   forbidden = foo/doz, user/*/private

is not supported

The attached patch changes this, and allows to use any path 
specification on the forbidden directive.

Cheers,

  - Salva

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
viewvc-forbidden-1.patch (text/x-patch, 1.5 KB)
Index: lib/vcauth/forbidden/__init__.py
===================================================================
--- lib/vcauth/forbidden/__init__.py	(revision 1698)
+++ lib/vcauth/forbidden/__init__.py	(working copy)
@@ -27,21 +27,24 @@
     if not path_parts:
       return 1
 
-    # If we have a single path part, we can't tell if this is a file
-    # or a directory.  So we ask our version control system.  If it's
-    # not a directory, we don't care about it.
-    if len(path_parts) == 1:
-      if self.root.itemtype(path_parts, rev) != vclib.DIR:
-        return 1
+    last_part = len(path_parts)
 
-    # At this point we're looking a path we believe to be a directory.
-    module = path_parts[0]
+    # Only directory paths are considered. We check if the user is
+    # requesting a file and in that case ignore the last path part
+    # representing the file name
+    if self.root.itemtype(path_parts, rev) != vclib.DIR:
+      last_part = last_part - 1
+
     default = 1
     for pat in self.forbidden:
       if pat[0] == '!':
         default = 0
-        if fnmatch.fnmatchcase(module, pat[1:]):
-          return 1
-      elif fnmatch.fnmatchcase(module, pat):
-        return 0
+      for i in range(last_part, 0, -1):
+        module = '/'.join(path_parts[0:i])
+        if pat[0] == '!':
+          if fnmatch.fnmatchcase(module, pat[1:]):
+            return 1
+        else:
+          if fnmatch.fnmatchcase(module, pat):
+            return 0
     return default
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.