Commits

Jason R. Coombs  committed 010633c

Worked out a fix for failing sandbox errors in Windows. Fixes #118.

  • Participants
  • Parent commits 903b483
  • Branches 0.6-maintenance

Comments (0)

Files changed (1)

File setuptools/sandbox.py

 
 _EXCEPTIONS = [os.devnull,]
 
+try:
+	gen_py = os.path.dirname(__import__('win32com.gen_py', fromlist=['__name__']).__file__)
+	_EXCEPTIONS.append(gen_py)
+except ImportError:
+	pass
+
 class DirectorySandbox(AbstractSandbox):
     """Restrict operations to a single subdirectory - pseudo-chroot"""
 
     def __init__(self, sandbox, exceptions=_EXCEPTIONS):
         self._sandbox = os.path.normcase(os.path.realpath(sandbox))
         self._prefix = os.path.join(self._sandbox,'')
-        self._exceptions = exceptions
+        self._exceptions = [os.path.normcase(os.path.realpath(path)) for path in exceptions]
         AbstractSandbox.__init__(self)
 
     def _violation(self, operation, *args, **kw):
         try:
             self._active = False
             realpath = os.path.normcase(os.path.realpath(path))
-            if (realpath in self._exceptions or realpath == self._sandbox
+            if (self._exempted(realpath) or realpath == self._sandbox
                 or realpath.startswith(self._prefix)):
                 return True
         finally:
             self._active = active
 
+    def _exempted(self, filepath):
+        exception_matches = map(filepath.startswith, self._exceptions)
+        return any(exception_matches)
+
     def _remap_input(self,operation,path,*args,**kw):
         """Called for path inputs"""
         if operation in self.write_ops and not self._ok(path):