Skip to content

Commit

Permalink
windows-compatible os_rename function
Browse files Browse the repository at this point in the history
windows libc rename() requires destination file path to not exist
  • Loading branch information
andrewrk committed Jan 19, 2018
1 parent 2eede35 commit 9f5c0b6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/os.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 9f5c0b6

Please sign in to comment.