summaryrefslogtreecommitdiff
path: root/git/util.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-06-13 16:13:35 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-06-13 16:13:35 +0200
commit9b6f38d02c8ed1fb07eb6782b918f31efc4c42f3 (patch)
tree66154f23e92f221c4c34d455d92938278ebab08d /git/util.py
parent59587d81412ca9da1fd06427efd864174d76c1c5 (diff)
downloadgitpython-9b6f38d02c8ed1fb07eb6782b918f31efc4c42f3.tar.gz
Submodule now uses a specialized method to remove its trees to allow read-only files to be removed on windows as well
Diffstat (limited to 'git/util.py')
-rw-r--r--git/util.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/git/util.py b/git/util.py
index 6576640a..a9e87d6f 100644
--- a/git/util.py
+++ b/git/util.py
@@ -8,6 +8,8 @@ import os
import re
import sys
import time
+import stat
+import shutil
import tempfile
import platform
@@ -23,10 +25,26 @@ from gitdb.util import (
__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
"join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList",
"BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists',
- 'RemoteProgress')
+ 'RemoteProgress', 'rmtree')
#{ Utility Methods
+def rmtree(path):
+ """Remove the given recursively.
+ :note: we use shutil rmtree but adjust its behaviour to see whether files that
+ couldn't be deleted are read-only. Windows will not remove them in that case"""
+ def onerror(func, path, exc_info):
+ if not os.access(path, os.W_OK):
+ # Is the error an access error ?
+ os.chmod(path, stat.S_IWUSR)
+ func(path)
+ else:
+ raise
+ # END end onerror
+ return shutil.rmtree(path, False, onerror)
+
+
+
def stream_copy(source, destination, chunk_size=512*1024):
"""Copy all data from the source stream into the destination stream in chunks
of size chunk_size