8000 Submodule now uses a specialized method to remove its trees to allow … · mrinal10/GitPython@9b6f38d · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b6f38d

Browse files
committed
Submodule now uses a specialized method to remove its trees to allow read-only files to be removed on windows as well
1 parent 59587d8 commit 9b6f38d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

git/objects/submodule/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
Iterable,
1414
join_path_native,
1515
to_native_path_linux,
16-
RemoteProgress
16+
RemoteProgress,
17+
rmtree
1718
)
1819

1920
from git.config import SectionConstraint
@@ -29,8 +30,6 @@
2930
import sys
3031
import time
3132

32-
import shutil
33-
3433
__all__ = ["Submodule", "UpdateProgress"]
3534

3635

@@ -622,7 +621,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
622621
if os.path.islink(mp):
623622
method = os.remove
624623
elif os.path.isdir(mp):
625-
method = shutil.rmtree
624+
method = rmtree
626625
elif os.path.exists(mp):
627626
raise AssertionError("Cannot forcibly delete repository as it was neither a link, nor a directory")
628627
#END handle brutal deletion
@@ -671,7 +670,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
671670
if not dry_run:
672671
wtd = mod.working_tree_dir
673672
del(mod) # release file-handles (windows)
674-
shutil.rmtree(wtd)
673+
rmtree(wtd)
675674
# END delete tree if possible
676675
# END handle force
677676
# END handle module deletion

git/util.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import re
99
import sys
1010
import time
11+
import stat
12+
import shutil
1113
import tempfile
1214
import platform
1315

@@ -23,10 +25,26 @@
2325
__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
2426
"join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList",
2527
"BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists',
26-
'RemoteProgress')
28+
'RemoteProgress', 'rmtree')
2729

2830
#{ Utility Methods
2931

32+
def rmtree(pat 8000 h):
33+
"""Remove the given recursively.
34+
:note: we use shutil rmtree but adjust its behaviour to see whether files that
35+
couldn't be deleted are read-only. Windows will not remove them in that case"""
36+
def onerror(func, path, exc_info):
37+
if not os.access(path, os.W_OK):
38+
# Is the error an access error ?
39+
os.chmod(path, stat.S_IWUSR)
40+
func(path)
41+
else:
42+
raise
43+
# END end onerror
44+
return shutil.rmtree(path, False, onerror)
45+
46+
47+
3048
def stream_copy(source, destination, chunk_size=512*1024):
3149
"""Copy all data from the source stream into the destination stream in chunks
3250
of size chunk_size

0 commit comments

Comments
 (0)
0