Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9b6f38d

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 parent59587d8 commit9b6f38d

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
fromgit.configimportSectionConstraint
@@ -29,8 +30,6 @@
2930
importsys
3031
importtime
3132

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

3635

@@ -622,7 +621,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
622621
ifos.path.islink(mp):
623622
method=os.remove
624623
elifos.path.isdir(mp):
625-
method=shutil.rmtree
624+
method=rmtree
626625
elifos.path.exists(mp):
627626
raiseAssertionError("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
ifnotdry_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
importre
99
importsys
1010
importtime
11+
importstat
12+
importshutil
1113
importtempfile
1214
importplatform
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+
defrmtree(path):
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+
defonerror(func,path,exc_info):
37+
ifnotos.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+
returnshutil.rmtree(path,False,onerror)
45+
46+
47+
3048
defstream_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)

[8]ページ先頭

©2009-2025 Movatter.jp