Skip to content

Commit 2073342

Browse files
EYVSTMMatthias Putz
authored and
Matthias Putz
committed
Fix: replacing shutils.rmtree with portable rmtree due to problem #34
1 parent 8b3ee8e commit 2073342

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

portable.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ def isUnix():
2020
def to_windows_path(path):
2121
return path.replace('/', '\\')
2222

23-
def rmtree(path):
24-
shutil.rmtree(path, onerror=onerror)
23+
def rmtree(top):
24+
for root, dirs, files in os.walk(top, topdown=False):
25+
for name in files:
26+
filename = os.path.join(root, name)
27+
os.chmod(filename, stat.S_IWRITE)
28+
os.remove(filename)
29+
for name in dirs:
30+
rmtree(os.path.join(root, name))
31+
os.rmdir(top)
2532

2633
def rename(src, dst):
2734
if isUnix():

project.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2166,10 +2166,10 @@ def _InitGitDir(self, mirror_git=None, force_sync=False):
21662166
if force_sync:
21672167
print("Retrying clone after deleting %s" % self.gitdir, file=sys.stderr)
21682168
try:
2169-
shutil.rmtree(os.path.realpath(self.gitdir))
2169+
portable.rmtree(os.path.realpath(self.gitdir))
21702170
if self.worktree and os.path.exists(
21712171
os.path.realpath(self.worktree)):
2172-
shutil.rmtree(os.path.realpath(self.worktree))
2172+
portable.rmtree(os.path.realpath(self.worktree))
21732173
return self._InitGitDir(mirror_git=mirror_git, force_sync=False)
21742174
except:
21752175
raise e
@@ -2210,9 +2210,9 @@ def _InitGitDir(self, mirror_git=None, force_sync=False):
22102210
self.config.SetString('core.bare', None)
22112211
except Exception:
22122212
if init_obj_dir and os.path.exists(self.objdir):
2213-
shutil.rmtree(self.objdir)
2213+
portable.rmtree(self.objdir)
22142214
if init_git_dir and os.path.exists(self.gitdir):
2215-
shutil.rmtree(self.gitdir)
2215+
portable.rmtree(self.gitdir)
22162216
raise
22172217

22182218
def _UpdateHooks(self):
@@ -2384,7 +2384,7 @@ def _InitWorkTree(self, force_sync=False):
23842384
except GitError as e:
23852385
if force_sync:
23862386
try:
2387-
shutil.rmtree(dotgit)
2387+
portable.rmtree(dotgit)
23882388
return self._InitWorkTree(force_sync=False)
23892389
except:
23902390
raise e
@@ -2402,7 +2402,7 @@ def _InitWorkTree(self, force_sync=False):
24022402
self._CopyAndLinkFiles()
24032403
except Exception:
24042404
if init_dotgit:
2405-
# shutil.rmtree(dotgit)
2405+
# portable.rmtree(dotgit)
24062406
portable.rmtree(dotgit)
24072407
raise
24082408

subcmds/gitc_delete.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ def Execute(self, opt, args):
5252
if not response == 'yes':
5353
print('Response was not "yes"\n Exiting...')
5454
sys.exit(1)
55-
shutil.rmtree(self.gitc_manifest.gitc_client_dir)
55+
portable.rmtree(self.gitc_manifest.gitc_client_dir)

subcmds/init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _SyncManifest(self, opt):
229229
# Better delete the manifest git dir if we created it; otherwise next
230230
# time (when user fixes problems) we won't go through the "is_new" logic.
231231
if is_new:
232-
shutil.rmtree(m.gitdir)
232+
portable.rmtree(m.gitdir)
233233
sys.exit(1)
234234

235235
if opt.manifest_branch:

subcmds/sync.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
from optparse import SUPPRESS_HELP
2020
import os
2121
import re
22+
import portable
2223
import shutil
2324
import socket
2425
import subprocess
2526
import sys
2627
import tempfile
2728
import time
29+
import stat
2830

2931
from pyversion import is_python3
3032
if is_python3():
@@ -490,7 +492,7 @@ def UpdateProjectList(self):
490492
else:
491493
print('Deleting obsolete path %s' % project.worktree,
492494
file=sys.stderr)
493-
shutil.rmtree(project.worktree)
495+
portable.rmtree(project.worktree)
494496
# Try deleting parent subdirs if they are empty
495497
project_dir = os.path.dirname(project.worktree)
496498
while project_dir != self.manifest.topdir:

0 commit comments

Comments
 (0)