Commit 2073342d by Erwan Yvin Committed by Matthias Putz

Fix: replacing shutils.rmtree with portable rmtree due to problem #34

parent 8b3ee8e2
......@@ -20,8 +20,15 @@ if isUnix():
def to_windows_path(path):
return path.replace('/', '\\')
def rmtree(path):
shutil.rmtree(path, onerror=onerror)
def rmtree(top):
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
filename = os.path.join(root, name)
os.chmod(filename, stat.S_IWRITE)
os.remove(filename)
for name in dirs:
rmtree(os.path.join(root, name))
os.rmdir(top)
def rename(src, dst):
if isUnix():
......
......@@ -2166,10 +2166,10 @@ class Project(object):
if force_sync:
print("Retrying clone after deleting %s" % self.gitdir, file=sys.stderr)
try:
shutil.rmtree(os.path.realpath(self.gitdir))
portable.rmtree(os.path.realpath(self.gitdir))
if self.worktree and os.path.exists(
os.path.realpath(self.worktree)):
shutil.rmtree(os.path.realpath(self.worktree))
portable.rmtree(os.path.realpath(self.worktree))
return self._InitGitDir(mirror_git=mirror_git, force_sync=False)
except:
raise e
......@@ -2210,9 +2210,9 @@ class Project(object):
self.config.SetString('core.bare', None)
except Exception:
if init_obj_dir and os.path.exists(self.objdir):
shutil.rmtree(self.objdir)
portable.rmtree(self.objdir)
if init_git_dir and os.path.exists(self.gitdir):
shutil.rmtree(self.gitdir)
portable.rmtree(self.gitdir)
raise
def _UpdateHooks(self):
......@@ -2384,7 +2384,7 @@ class Project(object):
except GitError as e:
if force_sync:
try:
shutil.rmtree(dotgit)
portable.rmtree(dotgit)
return self._InitWorkTree(force_sync=False)
except:
raise e
......@@ -2402,7 +2402,7 @@ class Project(object):
self._CopyAndLinkFiles()
except Exception:
if init_dotgit:
# shutil.rmtree(dotgit)
# portable.rmtree(dotgit)
portable.rmtree(dotgit)
raise
......
......@@ -52,4 +52,4 @@ and all locally downloaded sources.
if not response == 'yes':
print('Response was not "yes"\n Exiting...')
sys.exit(1)
shutil.rmtree(self.gitc_manifest.gitc_client_dir)
portable.rmtree(self.gitc_manifest.gitc_client_dir)
......@@ -229,7 +229,7 @@ to update the working directory files.
# Better delete the manifest git dir if we created it; otherwise next
# time (when user fixes problems) we won't go through the "is_new" logic.
if is_new:
shutil.rmtree(m.gitdir)
portable.rmtree(m.gitdir)
sys.exit(1)
if opt.manifest_branch:
......
......@@ -19,12 +19,14 @@ import netrc
from optparse import SUPPRESS_HELP
import os
import re
import portable
import shutil
import socket
import subprocess
import sys
import tempfile
import time
import stat
from pyversion import is_python3
if is_python3():
......@@ -490,7 +492,7 @@ later is required to fix a server side protocol bug.
else:
print('Deleting obsolete path %s' % project.worktree,
file=sys.stderr)
shutil.rmtree(project.worktree)
portable.rmtree(project.worktree)
# Try deleting parent subdirs if they are empty
project_dir = os.path.dirname(project.worktree)
while project_dir != self.manifest.topdir:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment