|
37 | 37 | import shutil
|
38 | 38 | import unittest
|
39 | 39 | import copy
|
40 |
| -from os import listdir |
| 40 | +import stat |
| 41 | +from os import listdir, chmod |
41 | 42 | from os.path import abspath, dirname, exists, join, isdir, isfile
|
42 | 43 | from tempfile import mkdtemp
|
43 | 44 | try:
|
@@ -171,9 +172,7 @@ def _run_test(self, testname):
|
171 | 172 | self._assert_dirs_equal(join(basepath, "[result]"),
|
172 | 173 | tmpdir,
|
173 | 174 | ignore=["%s.patch" % testname, ".svn", ".gitkeep", "[result]"])
|
174 |
| - |
175 |
| - |
176 |
| - shutil.rmtree(tmpdir) |
| 175 | + remove_tree_force(tmpdir) |
177 | 176 | return 0
|
178 | 177 |
|
179 | 178 |
|
@@ -362,7 +361,7 @@ def setUp(self):
|
362 | 361 |
|
363 | 362 | def tearDown(self):
|
364 | 363 | os.chdir(self.save_cwd)
|
365 |
| - shutil.rmtree(self.tmpdir) |
| 364 | + remove_tree_force(self.tmpdir) |
366 | 365 |
|
367 | 366 | def tmpcopy(self, filenames):
|
368 | 367 | """copy file(s) from test_dir to self.tmpdir"""
|
@@ -447,10 +446,15 @@ def test_fuzzy_patch_after(self):
|
447 | 446 | self.assertFalse(pto.apply(root=treeroot, fuzz=False))
|
448 | 447 |
|
449 | 448 | def test_unlink_backup_windows(self):
|
| 449 | + """ Apply patch to a read-only file and don't change its filemode |
| 450 | + """ |
450 | 451 | treeroot = join(self.tmpdir, 'rootparent')
|
451 | 452 | shutil.copytree(join(TESTS, '11permission'), treeroot)
|
452 |
| - pto = patch_ng.fromfile(join(TESTS, '11permission/11permission.patch')) |
| 453 | + pto = patch_ng.fromfile(join(TESTS, '11permission', '11permission.patch')) |
| 454 | + some_file = join(TESTS, '11permission', 'some_file') |
| 455 | + chmod(some_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) |
453 | 456 | self.assertTrue(pto.apply(root=treeroot))
|
| 457 | + self.assertTrue(os.stat(some_file).st_mode, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) |
454 | 458 |
|
455 | 459 |
|
456 | 460 | class TestHelpers(unittest.TestCase):
|
@@ -484,6 +488,14 @@ def test_pathstrip(self):
|
484 | 488 | self.assertEqual(patch_ng.pathstrip(b'path/name.diff', 1), b'name.diff')
|
485 | 489 | self.assertEqual(patch_ng.pathstrip(b'path/name.diff', 0), b'path/name.diff')
|
486 | 490 |
|
| 491 | +def remove_tree_force(folder): |
| 492 | + for root, dirs, files in os.walk(folder): |
| 493 | + for it in dirs: |
| 494 | + chmod(os.path.join(root, it), stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) |
| 495 | + for it in files: |
| 496 | + chmod(os.path.join(root, it), stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) |
| 497 | + shutil.rmtree(folder) |
| 498 | + |
487 | 499 | # ----------------------------------------------------------------------------
|
488 | 500 |
|
489 | 501 | if __name__ == '__main__':
|
|
0 commit comments