summaryrefslogtreecommitdiffstats
path: root/platform_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'platform_utils.py')
-rw-r--r--platform_utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/platform_utils.py b/platform_utils.py
index 4417c5a3..e0fa9dcc 100644
--- a/platform_utils.py
+++ b/platform_utils.py
@@ -13,6 +13,7 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16import errno
16import os 17import os
17import platform 18import platform
18import select 19import select
@@ -225,3 +226,19 @@ def handle_rmtree_error(function, path, excinfo):
225 # Allow deleting read-only files 226 # Allow deleting read-only files
226 os.chmod(path, stat.S_IWRITE) 227 os.chmod(path, stat.S_IWRITE)
227 function(path) 228 function(path)
229
230
231def rename(src, dst):
232 if isWindows():
233 # On Windows, rename fails if destination exists, see
234 # https://docs.python.org/2/library/os.html#os.rename
235 try:
236 os.rename(src, dst)
237 except OSError as e:
238 if e.errno == errno.EEXIST:
239 os.remove(dst)
240 os.rename(src, dst)
241 else:
242 raise
243 else:
244 os.rename(src, dst)