| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ | |||
| 18 | 18 | Iterable, | |
| 19 | 19 | join_path_native, | |
| 20 | 20 | to_native_path_linux, | |
| 21 | + rmtree | ||
| 21 | 22 | ) | |
| 22 | 23 | ||
| 23 | 24 | from git.db.interface import RemoteProgress | |
@@ -35,8 +36,6 @@ | |||
| 35 | 36 | import sys | |
| 36 | 37 | import time | |
| 37 | 38 | ||
| 38 | - import shutil | ||
| 39 | - | ||
| 40 | 39 | __all__ = ["Submodule", "UpdateProgress"] | |
| 41 | 40 | ||
| 42 | 41 | ||
@@ -634,7 +633,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False): | |||
| 634 | 633 | if os.path.islink(mp): | |
| 635 | 634 | method = os.remove | |
| 636 | 635 | elif os.path.isdir(mp): | |
| 637 | - method = shutil.rmtree | ||
| 636 | + method = rmtree | ||
| 638 | 637 | elif os.path.exists(mp): | |
| 639 | 638 | raise AssertionError("Cannot forcibly delete repository as it was neither a link, nor a directory") | |
| 640 | 639 | #END handle brutal deletion | |
@@ -683,7 +682,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False): | |||
| 683 | 682 | if not dry_run: | |
| 684 | 683 | wtd = mod.working_tree_dir | |
| 685 | 684 | del(mod) # release file-handles (windows) | |
| 686 | - shutil.rmtree(wtd) | ||
| 685 | + rmtree(wtd) | ||
| 687 | 686 | # END delete tree if possible | |
| 688 | 687 | # END handle force | |
| 689 | 688 | # END handle module deletion | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,12 +12,14 @@ | |||
| 12 | 12 | import errno | |
| 13 | 13 | import re | |
| 14 | 14 | import time | |
| 15 | + import stat | ||
| 16 | + import shutil | ||
| 15 | 17 | import tempfile | |
| 16 | 18 | ||
| 17 | 19 | __all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", | |
| 18 | 20 | "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", | |
| 19 | 21 | "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', | |
| 20 | - 'RepoAliasMixin', 'LockedFD', 'LazyMixin' ) | ||
| 22 | + 'RepoAliasMixin', 'LockedFD', 'LazyMixin', 'rmtree' ) | ||
| 21 | 23 | ||
| 22 | 24 | from cStringIO import StringIO | |
| 23 | 25 | ||
@@ -147,6 +149,19 @@ def is_git_dir(d): | |||
| 147 | 149 | os.readlink(headref).startswith('refs')) | |
| 148 | 150 | return False | |
| 149 | 151 | ||
| 152 | + def rmtree(path): | ||
| 153 | + """Remove the given recursively. | ||
| 154 | + :note: we use shutil rmtree but adjust its behaviour to see whether files that | ||
| 155 | + couldn't be deleted are read-only. Windows will not remove them in that case""" | ||
| 156 | + def onerror(func, path, exc_info): | ||
| 157 | + if not os.access(path, os.W_OK): | ||
| 158 | + # Is the error an access error ? | ||
| 159 | + os.chmod(path, stat.S_IWUSR) | ||
| 160 | + func(path) | ||
| 161 | + else: | ||
| 162 | + raise | ||
| 163 | + # END end onerror | ||
| 164 | + return shutil.rmtree(path, False, onerror) | ||
| 150 | 165 | ||
| 151 | 166 | def stream_copy(source, destination, chunk_size=512*1024): | |
| 152 | 167 | """Copy all data from the source stream into the destination stream in chunks | |
| Back | FazBrowse Home | New Git URL |
0 commit comments