diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
commit | a16e30d162c1c7408db7821e7b9513cefa09c6ca (patch) | |
tree | af752ba9ba44c547df39bb0af9bff79f610ba9d5 /src/os/dir_windows.go | |
parent | 91e4d2d57bc341dd82c98247117114c851380aef (diff) | |
parent | cf6cfba4d5358404dd890f6025e573a4b2156543 (diff) | |
download | go-git-dev.link.tar.gz |
[dev.link] all: merge branch 'master' into dev.linkdev.link
Clean merge.
Change-Id: Ia7b2808bc649790198d34c226a61d9e569084dc5
Diffstat (limited to 'src/os/dir_windows.go')
-rw-r--r-- | src/os/dir_windows.go | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/os/dir_windows.go b/src/os/dir_windows.go index 9e5d6bd505..253adad0b9 100644 --- a/src/os/dir_windows.go +++ b/src/os/dir_windows.go @@ -10,20 +10,14 @@ import ( "syscall" ) -func (file *File) readdir(n int) (fi []FileInfo, err error) { - if file == nil { - return nil, syscall.EINVAL - } +func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEntry, infos []FileInfo, err error) { if !file.isdir() { - return nil, &PathError{"Readdir", file.name, syscall.ENOTDIR} + return nil, nil, nil, &PathError{Op: "readdir", Path: file.name, Err: 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 { @@ -33,10 +27,7 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) { if e == syscall.ERROR_NO_MORE_FILES { break } else { - err = &PathError{"FindNextFile", file.name, e} - if !wantAll { - fi = nil - } + err = &PathError{Op: "FindNextFile", Path: file.name, Err: e} return } } @@ -46,24 +37,32 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) { if name == "." || name == ".." { // Useless names continue } - f := newFileStatFromWin32finddata(d) - f.name = name - f.path = file.dirinfo.path - f.appendNameToPath = true + if mode == readdirName { + names = append(names, name) + } else { + f := newFileStatFromWin32finddata(d) + f.name = name + f.path = file.dirinfo.path + f.appendNameToPath = true + if mode == readdirDirEntry { + dirents = append(dirents, dirEntry{f}) + } else { + infos = append(infos, f) + } + } n-- - fi = append(fi, f) } - if !wantAll && len(fi) == 0 { - return fi, io.EOF + if !wantAll && len(names)+len(dirents)+len(infos) == 0 { + return nil, nil, nil, io.EOF } - return fi, nil + return names, dirents, infos, 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 +type dirEntry struct { + fs *fileStat } + +func (de dirEntry) Name() string { return de.fs.Name() } +func (de dirEntry) IsDir() bool { return de.fs.IsDir() } +func (de dirEntry) Type() FileMode { return de.fs.Mode().Type() } +func (de dirEntry) Info() (FileInfo, error) { return de.fs, nil } |