Replace all os.remove calls
os.remove raises an exception when deleting read-only files on Windows. Replace all calls with calls to platform_utils.remove, which deals with deals with that issue. Change-Id: I4dc9e0c9a36b4238880520c69f5075eca40f3e66
This commit is contained in:
parent
e8595e9df7
commit
010fed7711
6 changed files with 43 additions and 24 deletions
|
@ -244,6 +244,23 @@ def rename(src, dst):
|
|||
os.rename(src, dst)
|
||||
|
||||
|
||||
def remove(path):
|
||||
"""Remove (delete) the file path. This is a replacement for os.remove, but
|
||||
allows deleting read-only files on Windows.
|
||||
"""
|
||||
if isWindows():
|
||||
try:
|
||||
os.remove(path)
|
||||
except OSError as e:
|
||||
if e.errno == errno.EACCES:
|
||||
os.chmod(path, stat.S_IWRITE)
|
||||
os.remove(path)
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
os.remove(path)
|
||||
|
||||
|
||||
def islink(path):
|
||||
"""Test whether a path is a symbolic link.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue