Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: Rename("oldDir", "newExistingDir") doesn't work on Windows #14527

Closed
RezaSR opened this issue Feb 26, 2016 · 7 comments
Closed

os: Rename("oldDir", "newExistingDir") doesn't work on Windows #14527

RezaSR opened this issue Feb 26, 2016 · 7 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@RezaSR
Copy link

RezaSR commented Feb 26, 2016

  1. What version of Go are you using (go version)?
    1.5.3
  2. What operating system and processor architecture are you using (go env)?
    windows - amd64
  3. What did you do?
    Rename a folder to new name that is already a folder. It works fine on linux-amd64 but cause error on windows-amd64

http://play.golang.org/p/m__tRp4mZh

  1. What did you expect to see?
    Replacement of newDir on windows as it does on linux.
  2. What did you see instead?
    Error. Access denied. Even running as administrator!
@bradfitz
Copy link
Contributor

/cc @alexbrainman

@bradfitz bradfitz added this to the Go1.7 milestone Feb 26, 2016
@bradfitz bradfitz changed the title os.Rename("oldDir", "newExistingDir") os: Rename("oldDir", "newExistingDir") doesn't work on Windows Feb 26, 2016
@RezaSR
Copy link
Author

RezaSR commented Feb 26, 2016

Thanks

@ianlancetaylor
Copy link
Contributor

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.

@alexbrainman
Copy link
Member

@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:

MOVEFILE_REPLACE_EXISTING ... This value cannot be used if lpNewFileName or lpExistingFileName names a directory.

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.

Alex

@alexbrand
Copy link

@alexbrainman is there anything blocking this? can I be of any help?

@alexbrainman
Copy link
Member

is there anything blocking this?

No, not really. Someone needs to come up with solution to this problem. I am not looking at this.

can I be of any help?

Feel free to propose solution to this.

Alex

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/31358 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

8 participants