github.com/charlievieth/fastwalk@v1.0.3/dirent_unix.go (about) 1 //go:build (aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd) && !appengine && !solaris 2 // +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd 3 // +build !appengine 4 // +build !solaris 5 6 package fastwalk 7 8 import ( 9 "io/fs" 10 "os" 11 ) 12 13 type unixDirent struct { 14 parent string 15 name string 16 typ os.FileMode 17 info *fileInfo 18 stat *fileInfo 19 } 20 21 func (d *unixDirent) Name() string { return d.name } 22 func (d *unixDirent) IsDir() bool { return d.typ.IsDir() } 23 func (d *unixDirent) Type() os.FileMode { return d.typ } 24 25 func (d *unixDirent) Info() (fs.FileInfo, error) { 26 info := loadFileInfo(&d.info) 27 info.once.Do(func() { 28 info.FileInfo, info.err = os.Lstat(d.parent + "/" + d.name) 29 }) 30 return info.FileInfo, info.err 31 } 32 33 func (d *unixDirent) Stat() (fs.FileInfo, error) { 34 if d.typ&os.ModeSymlink == 0 { 35 return d.Info() 36 } 37 stat := loadFileInfo(&d.stat) 38 stat.once.Do(func() { 39 stat.FileInfo, stat.err = os.Stat(d.parent + "/" + d.name) 40 }) 41 return stat.FileInfo, stat.err 42 } 43 44 func newUnixDirent(parent, name string, typ os.FileMode) *unixDirent { 45 return &unixDirent{ 46 parent: parent, 47 name: name, 48 typ: typ, 49 } 50 } 51 52 func fileInfoToDirEntry(dirname string, fi fs.FileInfo) fs.DirEntry { 53 info := &fileInfo{ 54 FileInfo: fi, 55 } 56 info.once.Do(func() {}) 57 return &unixDirent{ 58 parent: dirname, 59 name: fi.Name(), 60 typ: fi.Mode().Type(), 61 info: info, 62 } 63 }