Does your Windows app rely on os.Rename() or .Remove() ?

410 views
Skip to first unread message

Liam

unread,
Jun 21, 2019, 10:24:06 PM6/21/19
to golang-nuts
On Windows (but not elsewhere) this fails with a "sharing violation":

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()

Does anyone know of Windows apps that expect this error, which is undocumented?

Microsoft has suggested that Go on Windows should switch to Unix-like behavior:


Liam Breck

unread,
Jun 25, 2019, 11:25:24 AM6/25/19
to golang-nuts
Microsoft recommends changing this, so we need to know whether existing apps rely on it:

On Windows (but not elsewhere) this fails with a "sharing violation":
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()

Do you know of Windows apps that expect this error, which is undocumented in package "os" ?

Liam

unread,
Jun 30, 2019, 12:12:31 PM6/30/19
to golang-nuts
Microsoft has suggested that Go change syscall.Open() to fix this. Please pipe up if that might break your app!

Details quoted...

Liam

unread,
Jul 3, 2019, 1:09:27 PM7/3/19
to golang-nuts
[Sorry to keep re-posting this; I'm keeping it visible for infrequent readers]

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:

Jim Ancona

unread,
Jul 3, 2019, 8:49:23 PM7/3/19
to Liam, golang-nuts
On Wed, Jul 3, 2019 at 1:09 PM Liam <networ...@gmail.com> wrote:
[Sorry to keep re-posting this; I'm keeping it visible for infrequent readers]

I'm a frequent reader and I've now seen it four times. IMHO, that's enough.

Jim
  

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:

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1587c3db-4ce5-4572-bbb4-ed43c183d290%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages