Windows syscall.Open() change to fix os.Rename() & .Remove()

177 views
Skip to first unread message

Liam

unread,
Jul 10, 2019, 9:17:46 PM7/10/19
to golang-nuts
Microsoft recommends changing syscall.Open() for GOOS=windows to fix this. Pls reply if you know of existing apps that rely on it.

This code fails with a "sharing violation" on Windows. That behavior is undocumented in package "os".

path := "rename-after-open"
fd, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
if err != nil { ... }
err = os.Rename(path_a, path_b)            // or os.Remove(path)
if err != nil { ... }                      // sharing violation
fd.Close()

In this issue, Microsoft suggested that Go on Windows switch to Unix-like behavior:

I believe this will happen in pre-release 1.14.

Liam

unread,
Jul 31, 2019, 10:00:46 PM7/31/19
to golang-nuts
Microsoft recommends changing syscall.Open() for GOOS=windows to fix this. Pls reply if you know of existing apps that rely on it.

This code fails with a "sharing violation" on Windows. That behavior is undocumented in package "os".

path := "rename-after-open"
fd, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
if err != nil { ... }
err = os.Rename(path, path2)               // or os.Remove(path)
if err != nil { ... }                      // sharing violation
fd.Close()

In this issue, Microsoft suggested that Go on Windows switch to Unix-like behavior in Go 1.14:

I believe this will change early in pre-release 1.14.

Reto

unread,
Aug 4, 2019, 5:15:58 AM8/4/19
to golang-nuts
On Wed, Jul 31, 2019 at 07:00:46PM -0700, Liam wrote:
> In this issue, Microsoft suggested that Go on Windows switch to Unix-like
> behavior in Go 1.14:
> https://github.com/golang/go/issues/32088
>
> I believe this will change early in pre-release 1.14.

May I inquire as to why you believe that?
Reading the issue itself, nothing points to a favorable opinion to your change request.
At least not from the comments there.

Most of the members / contributors either speak clearly against it, or are very
cautious.

The only thing is the go1.4 milestone, but milestones tend to be shifted
around quite often.

Can you please point to the discussion where this was decided?

Tamás Gulácsi

unread,
Aug 4, 2019, 6:44:46 AM8/4/19
to golang-nuts
but that default won't fix (https://github.com/golang/go/issues/32088#issuecomment-500441971) the deviations from posix - a workaround is needed:

TL;DR; setting it by default would move the things to a little bit more POSIXy, but
possibly creating more hiddent deviations.

Tamás Gulácsi

Reto

unread,
Aug 4, 2019, 6:54:23 AM8/4/19
to golan...@googlegroups.com

>They did:
>https://github.com/golang/go/issues/32088#issuecomment-502850674

No, that's not a member of the go team.

>TL;DR; setting it by default would move the things to a little bit more
>
>POSIXy, but
>possibly creating more hiddent deviations.

yeah but that wasn't my question was it?

Liam Breck

unread,
Aug 4, 2019, 12:38:47 PM8/4/19
to golang-nuts
If you can point to an example that depends on the windows-specific error, could you post it in the issue?


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/aRvSo3iKvJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20190804091533.o2lz7s7gpyqotaz2%40feather.localdomain.
Reply all
Reply to author
Forward
0 new messages