authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-19 16:30:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-19 16:31:21-05:00
log9f5c0b6e6049fa53807be3334ce7ce96de2d24b4
tree7e0b2c7ed4a37bdd0b392ec2d713c7ff2cd5cf12
parent2eede35577fdd917e5680a2bf3c2cf64ff9339f2

windows-compatible os_rename function

windows libc rename() requires destination file path to not exist

1 files changed, 11 insertions(+), 0 deletions(-)

src/os.cpp+11
...@@ -794,7 +794,18 @@ int os_delete_file(Buf *path) {...@@ -794,7 +794,18 @@ int os_delete_file(Buf *path) {
794}794}
795795
796int os_rename(Buf *src_path, Buf *dest_path) {796int os_rename(Buf *src_path, Buf *dest_path) {
797 if (buf_eql_buf(src_path, dest_path)) {
798 return 0;
799 }
797 if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) {800 if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) {
801 // Windows requires the dest path to be missing
802 if (errno == EACCES) {
803 remove(buf_ptr(dest_path));
804 if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) {
805 return ErrorFileSystem;
806 }
807 return 0;
808 }
798 return ErrorFileSystem;809 return ErrorFileSystem;
799 }810 }
800 return 0;811 return 0;