summaryrefslogtreecommitdiffstats
path: root/platform_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'platform_utils.py')
-rw-r--r--platform_utils.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/platform_utils.py b/platform_utils.py
index 5741f4d3..0203249a 100644
--- a/platform_utils.py
+++ b/platform_utils.py
@@ -127,28 +127,27 @@ def rename(src, dst):
127 shutil.move(src, dst) 127 shutil.move(src, dst)
128 128
129 129
130def remove(path): 130def remove(path, missing_ok=False):
131 """Remove (delete) the file path. This is a replacement for os.remove that 131 """Remove (delete) the file path. This is a replacement for os.remove that
132 allows deleting read-only files on Windows, with support for long paths and 132 allows deleting read-only files on Windows, with support for long paths and
133 for deleting directory symbolic links. 133 for deleting directory symbolic links.
134 134
135 Availability: Unix, Windows.""" 135 Availability: Unix, Windows."""
136 if isWindows(): 136 longpath = _makelongpath(path) if isWindows() else path
137 longpath = _makelongpath(path) 137 try:
138 try: 138 os.remove(longpath)
139 os.remove(longpath) 139 except OSError as e:
140 except OSError as e: 140 if e.errno == errno.EACCES:
141 if e.errno == errno.EACCES: 141 os.chmod(longpath, stat.S_IWRITE)
142 os.chmod(longpath, stat.S_IWRITE) 142 # Directory symbolic links must be deleted with 'rmdir'.
143 # Directory symbolic links must be deleted with 'rmdir'. 143 if islink(longpath) and isdir(longpath):
144 if islink(longpath) and isdir(longpath): 144 os.rmdir(longpath)
145 os.rmdir(longpath)
146 else:
147 os.remove(longpath)
148 else: 145 else:
149 raise 146 os.remove(longpath)
150 else: 147 elif missing_ok and e.errno == errno.ENOENT:
151 os.remove(path) 148 pass
149 else:
150 raise
152 151
153 152
154def walk(top, topdown=True, onerror=None, followlinks=False): 153def walk(top, topdown=True, onerror=None, followlinks=False):