Commit 9f5c0b6e60

Andrew Kelley <superjoe30@gmail.com>
2018-01-19 22:30:50
windows-compatible os_rename function
windows libc rename() requires destination file path to not exist
1 parent 2eede35
Changed files (1)
src
src/os.cpp
@@ -794,7 +794,18 @@ int os_delete_file(Buf *path) {
 }
 
 int os_rename(Buf *src_path, Buf *dest_path) {
+    if (buf_eql_buf(src_path, dest_path)) {
+        return 0;
+    }
     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;
     }
     return 0;