diff options
author | Renaud Paquay <rpaquay@google.com> | 2016-11-11 14:25:29 -0800 |
---|---|---|
committer | Renaud Paquay <rpaquay@google.com> | 2017-08-31 13:49:36 -0700 |
commit | 010fed771183c23c0e7d04a4e7292782f68de9db (patch) | |
tree | 438b928fa1adaa7105d88462299513ca59c47c9f /platform_utils.py | |
parent | e8595e9df7980b0b7d9111de43d294c4439d474c (diff) | |
download | git-repo-010fed771183c23c0e7d04a4e7292782f68de9db.tar.gz |
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
Diffstat (limited to 'platform_utils.py')
-rw-r--r-- | platform_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
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): | |||
244 | os.rename(src, dst) | 244 | os.rename(src, dst) |
245 | 245 | ||
246 | 246 | ||
247 | def remove(path): | ||
248 | """Remove (delete) the file path. This is a replacement for os.remove, but | ||
249 | allows deleting read-only files on Windows. | ||
250 | """ | ||
251 | if isWindows(): | ||
252 | try: | ||
253 | os.remove(path) | ||
254 | except OSError as e: | ||
255 | if e.errno == errno.EACCES: | ||
256 | os.chmod(path, stat.S_IWRITE) | ||
257 | os.remove(path) | ||
258 | else: | ||
259 | raise | ||
260 | else: | ||
261 | os.remove(path) | ||
262 | |||
263 | |||
247 | def islink(path): | 264 | def islink(path): |
248 | """Test whether a path is a symbolic link. | 265 | """Test whether a path is a symbolic link. |
249 | 266 | ||