]> Cypherpunks repositories - gostls13.git/commitdiff
os: use FindFirstFile when GetFileAttributesEx fails in Stat
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 5 May 2016 02:44:28 +0000 (12:44 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Fri, 14 Oct 2016 03:58:15 +0000 (03:58 +0000)
Fixes #15355

Change-Id: Idbab7a627c5de249bb62d519c5a47f3d2f6c82a7
Reviewed-on: https://go-review.googlesource.com/22796
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/syscall/windows/syscall_windows.go
src/os/os_windows_test.go
src/os/stat_windows.go

index c4e59b28bd272aae635f5e51e633312b6364469c..4a30afbbfcfefe95771ac626f56035dfd59eb478 100644 (file)
@@ -7,6 +7,7 @@ package windows
 import "syscall"
 
 const (
+       ERROR_SHARING_VIOLATION      syscall.Errno = 32
        ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113
 )
 
index 741df3ff1e97e4188d86f033d8dfab5dcb0a4342..1a7946ae9fa9abbbb9b0fe02d829185e51f09064 100644 (file)
@@ -630,3 +630,14 @@ func TestReadStdin(t *testing.T) {
                }
        }
 }
+
+func TestStatPagefile(t *testing.T) {
+       _, err := os.Stat(`c:\pagefile.sys`)
+       if err == nil {
+               return
+       }
+       if os.IsNotExist(err) {
+               t.Skip(`skipping because c:\pagefile.sys is not found`)
+       }
+       t.Fatal(err)
+}
index c14abc7c4138af0cb720906303758baa68cc578a..694ff540bb32eeb4173e9398591bfc9055fb6040 100644 (file)
@@ -5,6 +5,7 @@
 package os
 
 import (
+       "internal/syscall/windows"
        "syscall"
        "unsafe"
 )
@@ -95,7 +96,23 @@ func Lstat(name string) (FileInfo, error) {
        }
        e = syscall.GetFileAttributesEx(namep, syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&fs.sys)))
        if e != nil {
-               return nil, &PathError{"GetFileAttributesEx", name, e}
+               if e != windows.ERROR_SHARING_VIOLATION {
+                       return nil, &PathError{"GetFileAttributesEx", name, e}
+               }
+               // try FindFirstFile now that GetFileAttributesEx failed
+               var fd syscall.Win32finddata
+               h, e2 := syscall.FindFirstFile(namep, &fd)
+               if e2 != nil {
+                       return nil, &PathError{"FindFirstFile", name, e}
+               }
+               syscall.FindClose(h)
+
+               fs.sys.FileAttributes = fd.FileAttributes
+               fs.sys.CreationTime = fd.CreationTime
+               fs.sys.LastAccessTime = fd.LastAccessTime
+               fs.sys.LastWriteTime = fd.LastWriteTime
+               fs.sys.FileSizeHigh = fd.FileSizeHigh
+               fs.sys.FileSizeLow = fd.FileSizeLow
        }
        fs.path = name
        if !isAbs(fs.path) {