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