Fix crash on Windows when crawling (#10385)

* readDirN: Check if file is directory

`syscall.FindNextFile` crashes if the handle is a file.

`errFileNotFound` matches 'unix' functionality: d19b434ffc/cmd/os-readdir_unix.go (L106)

Fixes #10384
master
Klaus Post 4 years ago committed by GitHub
parent 4b6585d249
commit 1c085f7d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      cmd/os-readdir_windows.go

@ -19,6 +19,7 @@
package cmd
import (
"io"
"os"
"syscall"
)
@ -79,10 +80,16 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
}
defer f.Close()
// Check if file or dir. This is the quickest way.
_, err = f.Seek(0, io.SeekStart)
if err == nil {
return nil, errFileNotFound
}
data := &syscall.Win32finddata{}
handle := syscall.Handle(f.Fd())
for count != 0 {
e := syscall.FindNextFile(syscall.Handle(f.Fd()), data)
e := syscall.FindNextFile(handle, data)
if e != nil {
if e == syscall.ERROR_NO_MORE_FILES {
break

Loading…
Cancel
Save