From 890bf001dbd4120ca8660d0e63594aa27d2a683f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 19 Jan 2018 16:53:08 -0500 Subject: [PATCH] os_rename uses MoveFileEx on windows --- src/os.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/os.cpp b/src/os.cpp index 48512a273d307b266fd2907e143274caddf1470b..4667554b04b975f0dbe8b3a330af5f64dd0fe680 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -797,17 +797,15 @@ int os_rename(Buf *src_path, Buf *dest_path) { if (buf_eql_buf(src_path, dest_path)) { return 0; } +#if defined(ZIG_OS_WINDOWS) + if (!MoveFileEx(buf_ptr(dest_path), buf_ptr(src_path), MOVEFILE_REPLACE_EXISTING)) { + return ErrorFileSystem; + } +#else if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) { - // Windows requires the dest path to be missing - if (errno == EACCES) { - remove(buf_ptr(dest_path)); - if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) { - return ErrorFileSystem; - } - return 0; - } return ErrorFileSystem; } +#endif return 0; } -- 2.54.0