mirror of
https://github.com/golang/go
synced 2024-10-01 16:28:33 -06:00
e83601b435
os.Stat implementation uses instructions described at https://blogs.msdn.microsoft.com/oldnewthing/20100212-00/?p=14963/ to distinguish symlinks. In particular, it calls GetFileAttributesEx or FindFirstFile and checks either WIN32_FILE_ATTRIBUTE_DATA.dwFileAttributes or WIN32_FIND_DATA.dwFileAttributes to see if FILE_ATTRIBUTES_REPARSE_POINT flag is set. And that seems to worked fine so far. But now we discovered that OneDrive root folder is determined as directory: c:\>dir C:\Users\Alex | grep OneDrive 30/11/2017 07:25 PM <DIR> OneDrive c:\> while Go identified it as symlink. But we did not follow Microsoft's advice to the letter - we never checked WIN32_FIND_DATA.Reserved0. And adding that extra check makes Go treat OneDrive as symlink. So use FindFirstFile and WIN32_FIND_DATA.Reserved0 to determine symlinks. Fixes #22579 Change-Id: I0cb88929eb8b47b1d24efaf1907ad5a0e20de83f Reviewed-on: https://go-review.googlesource.com/86556 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package os
|
|
|
|
import (
|
|
"io"
|
|
"runtime"
|
|
"syscall"
|
|
)
|
|
|
|
func (file *File) readdir(n int) (fi []FileInfo, err error) {
|
|
if file == nil {
|
|
return nil, syscall.EINVAL
|
|
}
|
|
if !file.isdir() {
|
|
return nil, &PathError{"Readdir", file.name, syscall.ENOTDIR}
|
|
}
|
|
wantAll := n <= 0
|
|
size := n
|
|
if wantAll {
|
|
n = -1
|
|
size = 100
|
|
}
|
|
fi = make([]FileInfo, 0, size) // Empty with room to grow.
|
|
d := &file.dirinfo.data
|
|
for n != 0 && !file.dirinfo.isempty {
|
|
if file.dirinfo.needdata {
|
|
e := file.pfd.FindNextFile(d)
|
|
runtime.KeepAlive(file)
|
|
if e != nil {
|
|
if e == syscall.ERROR_NO_MORE_FILES {
|
|
break
|
|
} else {
|
|
err = &PathError{"FindNextFile", file.name, e}
|
|
if !wantAll {
|
|
fi = nil
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
file.dirinfo.needdata = true
|
|
name := syscall.UTF16ToString(d.FileName[0:])
|
|
if name == "." || name == ".." { // Useless names
|
|
continue
|
|
}
|
|
f := newFileStatFromWin32finddata(d)
|
|
f.name = name
|
|
f.path = file.dirinfo.path
|
|
f.appendNameToPath = true
|
|
n--
|
|
fi = append(fi, f)
|
|
}
|
|
if !wantAll && len(fi) == 0 {
|
|
return fi, io.EOF
|
|
}
|
|
return fi, nil
|
|
}
|
|
|
|
func (file *File) readdirnames(n int) (names []string, err error) {
|
|
fis, err := file.Readdir(n)
|
|
names = make([]string, len(fis))
|
|
for i, fi := range fis {
|
|
names[i] = fi.Name()
|
|
}
|
|
return names, err
|
|
}
|