Merge fix to remove readonly files on Windows.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 1 Mar 2012 21:40:39 +0000 (22:40 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 1 Mar 2012 21:40:39 +0000 (22:40 +0100)
1  2 
NEWS
subvertpy/tests/__init__.py

diff --cc NEWS
index bd70c44242db25a1975b72c5f34ddccc61a2b5d5,454074ebb9627fac9d3754b827da089e48821cc6..b190f3781c80ba9e7d9e0fff180cb516ee0db853
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
@@@ -1,13 -1,5 +1,17 @@@
  0.8.11        UNRELEASED
  
 + IMPROVEMENTS
 +
 +  * Some fixes to help with porting to Python 3. (Yonggang Luo)
 +
++ TESTS
++
++  * Remove readonly files properly in tests.  (Yonggang Luo, #943131)
++
 + DOCUMENTATION
 +
 +  * Update documentation for building on Windows. (Yonggang Luo)
 +
  0.8.10        2012-01-23
  
   BUG FIXES
index c5b09b72e294a16fc8260f7c41710eb3fa999728,e09caedd8c596e36f5041b41e110ec5979629e8e..b7e3fd32d5b7955dd34ee3969def9188dc2ac554
@@@ -48,6 -49,22 +49,18 @@@ from subvertpy.ra import 
      )
  
  
 -def force_rm_handle(remove_path, path, excinfo):
 -    os.chmod(
 -        path,
 -        os.stat(path).st_mode | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH
 -    )
 -    remove_path(path)
 -
++def rmtree_with_readonly(path):
++    """Simple wrapper for shutil.rmtree that can remove read-only files.
 -def rmtree(path):
 -    """In Windows a read-only file cannot be removed, and shutil.rmtree fails.
 -    So we implement our own version of rmtree to address this issue.
++    In Windows a read-only file cannot be removed, and shutil.rmtree fails.
+     """
 -    if os.path.exists(path):
 -        shutil.rmtree(path, onerror=lambda func, path, e: force_rm_handle(func, path, e))
++    def force_rm_handle(remove_path, path, excinfo):
++        os.chmod(path, os.stat(path).st_mode | stat.S_IWUSR | stat.S_IWGRP |
++            stat.S_IWOTH)
++        remove_path(path)
++    shutil.rmtree(path, onerror=force_rm_handle)
  class TestCase(unittest.TestCase):
      """Base test case.
  
@@@ -81,7 -98,7 +94,7 @@@ class TestCaseInTempDir(TestCase)
      def tearDown(self):
          TestCase.tearDown(self)
          os.chdir(self._oldcwd)
-         shutil.rmtree(self.test_dir)
 -        rmtree(self.test_dir)
++        rmtree_with_readonly(self.test_dir)
  
  
  class TestFileEditor(object):