From 010fed771183c23c0e7d04a4e7292782f68de9db Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Fri, 11 Nov 2016 14:25:29 -0800 Subject: 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 --- platform_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'platform_utils.py') diff --git a/platform_utils.py b/platform_utils.py index 2ad56490..33cb2ec3 100644 --- a/platform_utils.py +++ b/platform_utils.py @@ -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. -- cgit v1.2.3-54-g00ecf