diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-11-05 22:24:01 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-11-05 22:24:01 +0100 |
commit | 179a1dcc65366a70369917d87d00b558a6d0c04d (patch) | |
tree | 1125bfcdde62dbaa23211b27568371ce5ce3cc29 /test/testlib/helper.py | |
parent | b372fdd54bab2ad6639756958978660b12095c3c (diff) | |
download | gitpython-179a1dcc65366a70369917d87d00b558a6d0c04d.tar.gz |
helper: repo creation functions now handle errors on windows during os.remove by changing the mode to 777 and delete the file again. Otherwise the whole operation would fail on read-only files. Why is windows as it is ? Why does it do that to me ?
Diffstat (limited to 'test/testlib/helper.py')
-rw-r--r-- | test/testlib/helper.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/test/testlib/helper.py b/test/testlib/helper.py index e9a15d5c..25b183a3 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -63,7 +63,18 @@ class ListProcessAdapter(object): poll = wait - + +def _rmtree_onerror(osremove, fullpath, exec_info): + """ + Handle the case on windows that read-only files cannot be deleted by + os.remove by setting it to mode 777, then retry deletion. + """ + if os.name != 'nt' or osremove is not os.remove: + raise + + os.chmod(fullpath, 0777) + os.remove(fullpath) + def with_bare_rw_repo(func): """ Decorator providing a specially made read-write repository to the test case @@ -83,7 +94,7 @@ def with_bare_rw_repo(func): return func(self, rw_repo) finally: rw_repo.git.clear_cache() - shutil.rmtree(repo_dir) + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) # END cleanup # END bare repo creator bare_repo_creator.__name__ = func.__name__ @@ -109,7 +120,7 @@ def with_rw_repo(working_tree_ref): return func(self, rw_repo) finally: rw_repo.git.clear_cache() - shutil.rmtree(repo_dir) + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) # END cleanup # END rw repo creator repo_creator.__name__ = func.__name__ @@ -186,8 +197,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref): finally: rw_repo.git.clear_cache() rw_remote_repo.git.clear_cache() - shutil.rmtree(repo_dir) - shutil.rmtree(remote_repo_dir) + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) + shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror) # END cleanup # END bare repo creator remote_repo_creator.__name__ = func.__name__ |