summaryrefslogtreecommitdiffstats
path: root/platform_utils.py
diff options
context:
space:
mode:
authorRenaud Paquay <rpaquay@google.com>2016-11-03 10:37:53 -0700
committerDavid Pursehouse <dpursehouse@collab.net>2017-05-29 19:32:31 +0900
commita65adf74f990eeac0d90011476376c7239cb7af5 (patch)
tree9278d9ce7c8d68a85dd049ed1ea5b64d84135fc0 /platform_utils.py
parentd5cec5e752821ca2710101b626b3a3ca07fdb7f8 (diff)
downloadgit-repo-a65adf74f990eeac0d90011476376c7239cb7af5.tar.gz
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
Diffstat (limited to 'platform_utils.py')
-rw-r--r--platform_utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/platform_utils.py b/platform_utils.py
index f4dfa0b1..4417c5a3 100644
--- a/platform_utils.py
+++ b/platform_utils.py
@@ -16,6 +16,8 @@
16import os 16import os
17import platform 17import platform
18import select 18import select
19import shutil
20import stat
19 21
20from Queue import Queue 22from Queue import Queue
21from threading import Thread 23from threading import Thread
@@ -210,3 +212,16 @@ def _winpath_is_valid(path):
210 return tail[0] == os.sep # "x:foo" is invalid 212 return tail[0] == os.sep # "x:foo" is invalid
211 else: 213 else:
212 return not drive # "x:" is invalid 214 return not drive # "x:" is invalid
215
216
217def rmtree(path):
218 if isWindows():
219 shutil.rmtree(path, onerror=handle_rmtree_error)
220 else:
221 shutil.rmtree(path)
222
223
224def handle_rmtree_error(function, path, excinfo):
225 # Allow deleting read-only files
226 os.chmod(path, stat.S_IWRITE)
227 function(path)