mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-07-04 20:17:16 +00:00
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
This commit is contained in:
committed by
David Pursehouse
parent
d5cec5e752
commit
a65adf74f9
@ -16,6 +16,8 @@
|
||||
import os
|
||||
import platform
|
||||
import select
|
||||
import shutil
|
||||
import stat
|
||||
|
||||
from Queue import Queue
|
||||
from threading import Thread
|
||||
@ -210,3 +212,16 @@ def _winpath_is_valid(path):
|
||||
return tail[0] == os.sep # "x:foo" is invalid
|
||||
else:
|
||||
return not drive # "x:" is invalid
|
||||
|
||||
|
||||
def rmtree(path):
|
||||
if isWindows():
|
||||
shutil.rmtree(path, onerror=handle_rmtree_error)
|
||||
else:
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
def handle_rmtree_error(function, path, excinfo):
|
||||
# Allow deleting read-only files
|
||||
os.chmod(path, stat.S_IWRITE)
|
||||
function(path)
|
||||
|
Reference in New Issue
Block a user