Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
os: Rename("oldDir", "newExistingDir") doesn't work on Windows #14527
Note that on GNU/Linux the os.Rename will only succeed if the destination directory is empty. If the destination directory has any files it will fail with ENOTEMPTY. I think we should consider checking for and rejecting rename to an existing directory on non-Windows.
added a commit
Feb 26, 2016
@bradfitz, latest change (CL 6140) of windows os.Rename introduced use of MoveFileEx. Our code uses MOVEFILE_REPLACE_EXISTING flag, I guess, to make "overwriting of destination file" work. But according to the doco https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx:
That is why, I guess, MoveFileEx return ERROR_ACCESS_DENIED in that scenario. (Running example above I see MoveFileEx return ERROR_ACCESS_DENIED).
I will let you decide what to do here.