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

Windows os.Rename bad #3366

Closed
gopherbot opened this issue Mar 21, 2012 · 7 comments
Closed

Windows os.Rename bad #3366

gopherbot opened this issue Mar 21, 2012 · 7 comments

Comments

@gopherbot
Copy link
Contributor

by kfox1111:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull", "hg update default", rebuild, and
retry
what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
1. os.Rename('foo', 'file.that.already.exists')

What is the expected output?
The file be overwritten.

What do you see instead?
Error that file exists.

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g

Which operating system are you using?
Windows

Which revision are you using?  (hg identify)
Newest weekly.

Please provide any additional information below.
@4ad
Copy link
Member

4ad commented Mar 21, 2012

Comment 1:

Package os provides a consistent interface to the system, but the behavior of the
implementation might vary between systems due to system-specific rules. This is how
Windows rename works, I'm not sure it's our job to "fix" it.

@4ad
Copy link
Member

4ad commented Mar 21, 2012

Comment 2:

Package os provides a consistent interface to the system,
but the behavior of the implementation might vary between
systems due to system-specific rules.  This is how Windows
rename works, I'm not sure it's our job to "fix" it.

@ianlancetaylor
Copy link
Member

Comment 3:

As far as I know, there is no way to handle os.Rename such that it is equivalent on
Windows and POSIX systems.  In particular, on POSIX os.Rename is atomic, in the sense
that if the destination path already exists, any other process can always open the
destination path and get either the old file or the new file.  Since we can't provide
identical semantics on different operating systems, I don't think we should try to go
beyond what the OS provides.  There is no one right choice.

Status changed to WorkingAsIntended.

@minux
Copy link
Member

minux commented Jun 3, 2013

Comment 4:

Issue #5620 has been merged into this issue.

@gopherbot
Copy link
Contributor Author

Comment 5 by MartyMacGyver:

I recommend this bug be reopened and reconsidered. Other languages have encountered and
tackled this problem successfully in Windows. As one example, the report of the same
issue in Python led to a detailed discussion and ultimately had a successful resolution
(http://bugs.python.org/issue8828). The resolution of this bug in other Go projects
follows the same pattern - effectively creating an os.Replace() function for this
circumstance, using the Windows MoveFileEx api. Whether os.Rename() is enhanced to
properly handle Windows cases or a new os.Replace() function is created that satisfies
the same criteria, it would prevent everyone from re-inventing the same wheel virtually
the same way simply to sidestep this bug.

@alexbrainman
Copy link
Member

Comment 6:

MartyMacGyver, if you are asking for new os function, you should create new issue.
Behaviour of os.Rename is not up for a discussion.
Alex

@gopherbot
Copy link
Contributor Author

Comment 7 by MartyMacGyver:

Understood. I've created a new issue #8914 for this purpose.

tv42 added a commit to tv42/go-datastore that referenced this issue Apr 24, 2015
…Ex directly

For background, see golang/go#3366

Here's the failure seen:

    --- FAIL: TestPutOverwrite (0.03s)
    	flatfs_test.go:118: Put fail: rename C:\Users\gates\AppData\Local\Temp\test-datastore-flatfs-679014441\7175\put- 717454915 C:\Users\gates\AppData\Local\Temp\test-datastore-flatfs-679014441/7175/71757578.data: Cannot create a file when that file already exists.
tv42 added a commit to tv42/go-datastore that referenced this issue Apr 25, 2015
…Ex directly

For background, see golang/go#3366

Here's the failure seen:

    --- FAIL: TestPutOverwrite (0.03s)
    	flatfs_test.go:118: Put fail: rename C:\Users\gates\AppData\Local\Temp\test-datastore-flatfs-679014441\7175\put- 717454915 C:\Users\gates\AppData\Local\Temp\test-datastore-flatfs-679014441/7175/71757578.data: Cannot create a file when that file already exists.
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants