vfs: fix truncation work-around on Windows

This no longer needs to deal with O_RDONLY and O_TRUNC since we
disallow this earlier.  This also fixes the code to just do it for
O_APPEND, not for everything.
This commit is contained in:
Nick Craig-Wood 2018-02-26 19:46:38 +00:00
parent f57e92b9a5
commit c3d0f68923

View File

@ -170,7 +170,7 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) {
// Windows doesn't seem to deal well with O_TRUNC and
// certain access modes so so truncate the file if it
// exists in these cases.
if runtime.GOOS == "windows" && (fh.flags&accessModeMask == os.O_RDONLY || fh.flags|os.O_APPEND != 0) {
if runtime.GOOS == "windows" && fh.flags&os.O_APPEND != 0 {
cacheFileOpenFlags &^= os.O_TRUNC
_, err = os.Stat(fh.osPath)
if err == nil {