You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was toying with atomic file operations, and noticed os.Rename for the Microsoft implementation uses MoveFileW, yet MoveFileExW exists which accepts a flags argument. os.Rename on everything not Windows (and plan9) is "atomic," meaning that it replaces the destination if it exists, with no opportunity to crash in user space. In Microsoft, if the destination exists, the os.Rename operation fails and the programmer is expected to be able to remove and replace the destination themselves without any way to prevent race conditions or interruptions halfway through.
This will confuse any programmers on Microsoft, performing needless existence checks when calling os.Rename on non-Microsoft, and any programmers not on Microsoft will be rather miffed at being unable to do safe file renames on Microsoft.
The non-Microsoft behavior can be achieved in Microsoft using MoveFileExW (I think) by passing certain flags to the procedure. So I recommend that the Go language adopt MoveFileExW as the system call for Microsoft, when using os.Rename, so that os.Rename behaves the same on Microsoft, and off Microsoft.
It should be about a 2 line patch, but I have no way to test whether it works correctly or not. Just throwing it out there.
using go 1.5 btw, from a recent git pull
go version devel +e8fc93e Fri May 8 04:23:43 2015 +0000 linux/amd64
The text was updated successfully, but these errors were encountered:
I was toying with atomic file operations, and noticed os.Rename for the Microsoft implementation uses MoveFileW, yet MoveFileExW exists which accepts a flags argument. os.Rename on everything not Windows (and plan9) is "atomic," meaning that it replaces the destination if it exists, with no opportunity to crash in user space. In Microsoft, if the destination exists, the os.Rename operation fails and the programmer is expected to be able to remove and replace the destination themselves without any way to prevent race conditions or interruptions halfway through.
This will confuse any programmers on Microsoft, performing needless existence checks when calling os.Rename on non-Microsoft, and any programmers not on Microsoft will be rather miffed at being unable to do safe file renames on Microsoft.
The non-Microsoft behavior can be achieved in Microsoft using MoveFileExW (I think) by passing certain flags to the procedure. So I recommend that the Go language adopt MoveFileExW as the system call for Microsoft, when using os.Rename, so that os.Rename behaves the same on Microsoft, and off Microsoft.
It should be about a 2 line patch, but I have no way to test whether it works correctly or not. Just throwing it out there.
using go 1.5 btw, from a recent git pull
go version devel +e8fc93e Fri May 8 04:23:43 2015 +0000 linux/amd64
The text was updated successfully, but these errors were encountered: