summaryrefslogtreecommitdiff
path: root/gitdb/util.py
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-02 02:03:13 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-10-24 15:17:00 +0200
commit758c29306f509008d80ee84443e04cf6655215ea (patch)
tree22a69d63f150647e8f0263ba77bab6c76f9a58f8 /gitdb/util.py
parent2ec8c99e52290b88a6816df7cef0eff8df81c0b7 (diff)
downloadgitdb-758c29306f509008d80ee84443e04cf6655215ea.tar.gz
feat(io): breaking API: retrofit Packers as context-managers!
+ Packers MUST be invoked inside `Withh...` blocks, or `_cursor` won't exist! + Had to drop NotLazy for their hierarchy :-( + Count entrances/exits. + feat(util: add `rmtree()` for READ_ONLY files on Windows. 3-->2 Windows TCs now fail.
Diffstat (limited to 'gitdb/util.py')
-rw-r--r--gitdb/util.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/gitdb/util.py b/gitdb/util.py
index 821fc9b..e6ed8a3 100644
--- a/gitdb/util.py
+++ b/gitdb/util.py
@@ -16,6 +16,8 @@ from smmap import (
SlidingWindowMapBuffer
)
import logging
+import stat
+import shutil
# initialize our global memory manager instance
# Use it to free cached (and unused) resources.
@@ -118,6 +120,24 @@ def byte_ord(b):
#{ Routines
+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):
+ # Is the error an access error ?
+ os.chmod(path, stat.S_IWUSR)
+
+ try:
+ func(path) # Will scream if still not possible to delete.
+ except Exception as ex:
+ raise
+
+ return shutil.rmtree(path, False, onerror)
+
+
def make_sha(source=''.encode("ascii")):
"""A python2.4 workaround for the sha/hashlib module fiasco