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
diff --git a/platform_utils.py b/platform_utils.py
index 2ad5649..33cb2ec 100644
--- a/platform_utils.py
+++ b/platform_utils.py
@@ -244,6 +244,23 @@
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.