Workaround shutil.rmtree limitation on Windows
By default, shutil.rmtree raises an exception when deleting readonly
files on Windows.
Replace all shutil.rmtree with platform_utils.rmtree, which adds an
error handler to make files read-write when they can't be deleted.
Change-Id: I9cfea9a7b3703fb16a82cf69331540c2c179ed53
diff --git a/subcmds/gitc_delete.py b/subcmds/gitc_delete.py
index 19caac5..54f62f4 100644
--- a/subcmds/gitc_delete.py
+++ b/subcmds/gitc_delete.py
@@ -14,10 +14,10 @@
# limitations under the License.
from __future__ import print_function
-import shutil
import sys
from command import Command, GitcClientCommand
+import platform_utils
from pyversion import is_python3
if not is_python3():
@@ -50,4 +50,4 @@
if not response == 'yes':
print('Response was not "yes"\n Exiting...')
sys.exit(1)
- shutil.rmtree(self.gitc_manifest.gitc_client_dir)
+ platform_utils.rmtree(self.gitc_manifest.gitc_client_dir)
diff --git a/subcmds/init.py b/subcmds/init.py
index 65dfd1f..e647091 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -17,7 +17,6 @@
import os
import platform
import re
-import shutil
import sys
from pyversion import is_python3
@@ -35,6 +34,7 @@
from project import SyncBuffer
from git_config import GitConfig
from git_command import git_require, MIN_GIT_VERSION
+import platform_utils
class Init(InteractiveCommand, MirrorSafeCommand):
common = True
@@ -252,7 +252,7 @@
# 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)
+ platform_utils.rmtree(m.gitdir)
sys.exit(1)
if opt.manifest_branch:
diff --git a/subcmds/sync.py b/subcmds/sync.py
index ef02327..797fc40 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -19,7 +19,6 @@
from optparse import SUPPRESS_HELP
import os
import re
-import shutil
import socket
import subprocess
import sys
@@ -73,6 +72,7 @@
from project import RemoteSpec
from command import Command, MirrorSafeCommand
from error import RepoChangedException, GitError, ManifestParseError
+import platform_utils
from project import SyncBuffer
from progress import Progress
from wrapper import Wrapper
@@ -473,7 +473,7 @@
# working git repository around. There shouldn't be any git projects here,
# so rmtree works.
try:
- shutil.rmtree(os.path.join(path, '.git'))
+ platform_utils.rmtree(os.path.join(path, '.git'))
except OSError:
print('Failed to remove %s' % os.path.join(path, '.git'), file=sys.stderr)
print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)