1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:04:39 -07:00

rename os.Dir to os.FileInfo

R=rsc
CC=golang-dev
https://golang.org/cl/902042
This commit is contained in:
Rob Pike 2010-04-09 11:36:40 -07:00
parent a17544f283
commit 3ddeef8153
14 changed files with 143 additions and 142 deletions

View File

@ -116,21 +116,21 @@ func registerPublicHandlers(mux *http.ServeMux) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Predicates and small utility functions // Predicates and small utility functions
func isGoFile(dir *os.Dir) bool { func isGoFile(f *os.FileInfo) bool {
return dir.IsRegular() && return f.IsRegular() &&
!strings.HasPrefix(dir.Name, ".") && // ignore .files !strings.HasPrefix(f.Name, ".") && // ignore .files
pathutil.Ext(dir.Name) == ".go" pathutil.Ext(f.Name) == ".go"
} }
func isPkgFile(dir *os.Dir) bool { func isPkgFile(f *os.FileInfo) bool {
return isGoFile(dir) && return isGoFile(f) &&
!strings.HasSuffix(dir.Name, "_test.go") // ignore test files !strings.HasSuffix(f.Name, "_test.go") // ignore test files
} }
func isPkgDir(dir *os.Dir) bool { func isPkgDir(f *os.FileInfo) bool {
return dir.IsDirectory() && len(dir.Name) > 0 && dir.Name[0] != '_' return f.IsDirectory() && len(f.Name) > 0 && f.Name[0] != '_'
} }
@ -789,7 +789,7 @@ func timeFmt(w io.Writer, x interface{}, format string) {
// Template formatter for "dir/" format. // Template formatter for "dir/" format.
func dirslashFmt(w io.Writer, x interface{}, format string) { func dirslashFmt(w io.Writer, x interface{}, format string) {
if x.(*os.Dir).IsDirectory() { if x.(*os.FileInfo).IsDirectory() {
w.Write([]byte{'/'}) w.Write([]byte{'/'})
} }
} }
@ -1196,7 +1196,7 @@ type httpHandler struct {
// //
func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInfoMode) PageInfo { func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInfoMode) PageInfo {
// filter function to select the desired .go files // filter function to select the desired .go files
filter := func(d *os.Dir) bool { filter := func(d *os.FileInfo) bool {
// If we are looking at cmd documentation, only accept // If we are looking at cmd documentation, only accept
// the special fakePkgFile containing the documentation. // the special fakePkgFile containing the documentation.
return isPkgFile(d) && (h.isPkg || d.Name == fakePkgFile) return isPkgFile(d) && (h.isPkg || d.Name == fakePkgFile)

View File

@ -578,17 +578,17 @@ func (x *Indexer) Visit(node interface{}) ast.Visitor {
} }
func (x *Indexer) VisitDir(path string, d *os.Dir) bool { func (x *Indexer) VisitDir(path string, f *os.FileInfo) bool {
return true return true
} }
func (x *Indexer) VisitFile(path string, d *os.Dir) { func (x *Indexer) VisitFile(path string, f *os.FileInfo) {
if !isGoFile(d) { if !isGoFile(f) {
return return
} }
if excludeTestFiles && (!isPkgFile(d) || strings.HasPrefix(path, "test/")) { if excludeTestFiles && (!isPkgFile(f) || strings.HasPrefix(path, "test/")) {
return return
} }

View File

@ -80,9 +80,9 @@ func initPrinterMode() {
} }
func isGoFile(d *os.Dir) bool { func isGoFile(f *os.FileInfo) bool {
// ignore non-Go files // ignore non-Go files
return d.IsRegular() && !strings.HasPrefix(d.Name, ".") && strings.HasSuffix(d.Name, ".go") return f.IsRegular() && !strings.HasPrefix(f.Name, ".") && strings.HasSuffix(f.Name, ".go")
} }
@ -145,13 +145,13 @@ func processFileByName(filename string) (err os.Error) {
type fileVisitor chan os.Error type fileVisitor chan os.Error
func (v fileVisitor) VisitDir(path string, d *os.Dir) bool { func (v fileVisitor) VisitDir(path string, f *os.FileInfo) bool {
return true return true
} }
func (v fileVisitor) VisitFile(path string, d *os.Dir) { func (v fileVisitor) VisitFile(path string, f *os.FileInfo) {
if isGoFile(d) { if isGoFile(f) {
v <- nil // synchronize error handler v <- nil // synchronize error handler
if err := processFileByName(path); err != nil { if err := processFileByName(path); err != nil {
v <- err v <- err

View File

@ -173,14 +173,14 @@ func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (map[string]*as
// ParseDir calls ParseFile for the files in the directory specified by path and // ParseDir calls ParseFile for the files in the directory specified by path and
// returns a map of package name -> package AST with all the packages found. If // returns a map of package name -> package AST with all the packages found. If
// filter != nil, only the files with os.Dir entries passing through the filter // filter != nil, only the files with os.FileInfo entries passing through the filter
// are considered. The mode bits are passed to ParseFile unchanged. // are considered. The mode bits are passed to ParseFile unchanged.
// //
// If the directory couldn't be read, a nil map and the respective error are // If the directory couldn't be read, a nil map and the respective error are
// returned. If a parse error occured, a non-nil but incomplete map and the // returned. If a parse error occured, a non-nil but incomplete map and the
// error are returned. // error are returned.
// //
func ParseDir(path string, filter func(*os.Dir) bool, mode uint) (map[string]*ast.Package, os.Error) { func ParseDir(path string, filter func(*os.FileInfo) bool, mode uint) (map[string]*ast.Package, os.Error) {
fd, err := os.Open(path, os.O_RDONLY, 0) fd, err := os.Open(path, os.O_RDONLY, 0)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -79,7 +79,7 @@ func nameFilter(filename string) bool {
} }
func dirFilter(d *os.Dir) bool { return nameFilter(d.Name) } func dirFilter(f *os.FileInfo) bool { return nameFilter(f.Name) }
func TestParse4(t *testing.T) { func TestParse4(t *testing.T) {

View File

@ -27,12 +27,12 @@ func ReadFile(filename string) ([]byte, os.Error) {
return nil, err return nil, err
} }
defer f.Close() defer f.Close()
// It's a good but not certain bet that Stat will tell us exactly how much to // It's a good but not certain bet that FileInfo will tell us exactly how much to
// read, so let's try it but be prepared for the answer to be wrong. // read, so let's try it but be prepared for the answer to be wrong.
dir, err := f.Stat() fi, err := f.Stat()
var n uint64 var n uint64
if err == nil && dir.Size < 2e9 { // Don't preallocate a huge buffer, just in case. if err == nil && fi.Size < 2e9 { // Don't preallocate a huge buffer, just in case.
n = dir.Size n = fi.Size
} }
// Add a little extra in case Size is zero, and to avoid another allocation after // Add a little extra in case Size is zero, and to avoid another allocation after
// Read has filled the buffer. // Read has filled the buffer.
@ -63,15 +63,15 @@ func WriteFile(filename string, data []byte, perm int) os.Error {
} }
// A dirList implements sort.Interface. // A dirList implements sort.Interface.
type dirList []*os.Dir type fileInfoList []*os.FileInfo
func (d dirList) Len() int { return len(d) } func (f fileInfoList) Len() int { return len(f) }
func (d dirList) Less(i, j int) bool { return d[i].Name < d[j].Name } func (f fileInfoList) Less(i, j int) bool { return f[i].Name < f[j].Name }
func (d dirList) Swap(i, j int) { d[i], d[j] = d[j], d[i] } func (f fileInfoList) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
// ReadDir reads the directory named by dirname and returns // ReadDir reads the directory named by dirname and returns
// a list of sorted directory entries. // a list of sorted directory entries.
func ReadDir(dirname string) ([]*os.Dir, os.Error) { func ReadDir(dirname string) ([]*os.FileInfo, os.Error) {
f, err := os.Open(dirname, os.O_RDONLY, 0) f, err := os.Open(dirname, os.O_RDONLY, 0)
if err != nil { if err != nil {
return nil, err return nil, err
@ -81,10 +81,10 @@ func ReadDir(dirname string) ([]*os.Dir, os.Error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
dirs := make(dirList, len(list)) fi := make(fileInfoList, len(list))
for i := range list { for i := range list {
dirs[i] = &list[i] fi[i] = &list[i]
} }
sort.Sort(dirs) sort.Sort(fi)
return dirs, nil return fi, nil
} }

View File

@ -258,12 +258,12 @@ func Mkdir(name string, perm int) Error {
return nil return nil
} }
// Stat returns a Dir structure describing the named file and an error, if any. // Stat returns a FileInfo structure describing the named file and an error, if any.
// If name names a valid symbolic link, the returned Dir describes // If name names a valid symbolic link, the returned FileInfo describes
// the file pointed at by the link and has dir.FollowedSymlink set to true. // the file pointed at by the link and has fi.FollowedSymlink set to true.
// If name names an invalid symbolic link, the returned Dir describes // If name names an invalid symbolic link, the returned FileInfo describes
// the link itself and has dir.FollowedSymlink set to false. // the link itself and has fi.FollowedSymlink set to false.
func Stat(name string) (dir *Dir, err Error) { func Stat(name string) (fi *FileInfo, err Error) {
var lstat, stat syscall.Stat_t var lstat, stat syscall.Stat_t
e := syscall.Lstat(name, &lstat) e := syscall.Lstat(name, &lstat)
if e != 0 { if e != 0 {
@ -276,38 +276,39 @@ func Stat(name string) (dir *Dir, err Error) {
statp = &stat statp = &stat
} }
} }
return dirFromStat(name, new(Dir), &lstat, statp), nil return fileInfoFromStat(name, new(FileInfo), &lstat, statp), nil
} }
// Stat returns the Dir structure describing file. // Stat returns the FileInfo structure describing file.
// It returns the Dir and an error, if any. // It returns the FileInfo and an error, if any.
func (file *File) Stat() (dir *Dir, err Error) { func (file *File) Stat() (fi *FileInfo, err Error) {
var stat syscall.Stat_t var stat syscall.Stat_t
e := syscall.Fstat(file.fd, &stat) e := syscall.Fstat(file.fd, &stat)
if e != 0 { if e != 0 {
return nil, &PathError{"stat", file.name, Errno(e)} return nil, &PathError{"stat", file.name, Errno(e)}
} }
return dirFromStat(file.name, new(Dir), &stat, &stat), nil return fileInfoFromStat(file.name, new(FileInfo), &stat, &stat), nil
} }
// Lstat returns the Dir structure describing the named file and an error, if any. // Lstat returns the FileInfo structure describing the named file and an
// If the file is a symbolic link, the returned Dir describes the // error, if any. If the file is a symbolic link, the returned FileInfo
// symbolic link. Lstat makes no attempt to follow the link. // describes the symbolic link. Lstat makes no attempt to follow the link.
func Lstat(name string) (dir *Dir, err Error) { func Lstat(name string) (fi *FileInfo, err Error) {
var stat syscall.Stat_t var stat syscall.Stat_t
e := syscall.Lstat(name, &stat) e := syscall.Lstat(name, &stat)
if e != 0 { if e != 0 {
return nil, &PathError{"lstat", name, Errno(e)} return nil, &PathError{"lstat", name, Errno(e)}
} }
return dirFromStat(name, new(Dir), &stat, &stat), nil return fileInfoFromStat(name, new(FileInfo), &stat, &stat), nil
} }
// Readdir reads the contents of the directory associated with file and // Readdir reads the contents of the directory associated with file and
// returns an array of up to count Dir structures, as would be returned // returns an array of up to count FileInfo structures, as would be returned
// by Stat, in directory order. Subsequent calls on the same file will yield further Dirs. // by Stat, in directory order. Subsequent calls on the same file will yield
// further FileInfos.
// A negative count means to read until EOF. // A negative count means to read until EOF.
// Readdir returns the array and an Error, if any. // Readdir returns the array and an Error, if any.
func (file *File) Readdir(count int) (dirs []Dir, err Error) { func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
dirname := file.name dirname := file.name
if dirname == "" { if dirname == "" {
dirname = "." dirname = "."
@ -317,13 +318,13 @@ func (file *File) Readdir(count int) (dirs []Dir, err Error) {
if err1 != nil { if err1 != nil {
return nil, err1 return nil, err1
} }
dirs = make([]Dir, len(names)) fi = make([]FileInfo, len(names))
for i, filename := range names { for i, filename := range names {
dirp, err := Lstat(dirname + filename) fip, err := Lstat(dirname + filename)
if dirp == nil || err != nil { if fip == nil || err != nil {
dirs[i].Name = filename // rest is already zeroed out fi[i].Name = filename // rest is already zeroed out
} else { } else {
dirs[i] = *dirp fi[i] = *fip
} }
} }
return return

View File

@ -10,29 +10,29 @@ func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
dir.Dev = uint64(stat.Dev) fi.Dev = uint64(stat.Dev)
dir.Ino = stat.Ino fi.Ino = stat.Ino
dir.Nlink = uint64(stat.Nlink) fi.Nlink = uint64(stat.Nlink)
dir.Mode = uint32(stat.Mode) fi.Mode = uint32(stat.Mode)
dir.Uid = stat.Uid fi.Uid = stat.Uid
dir.Gid = stat.Gid fi.Gid = stat.Gid
dir.Rdev = uint64(stat.Rdev) fi.Rdev = uint64(stat.Rdev)
dir.Size = uint64(stat.Size) fi.Size = uint64(stat.Size)
dir.Blksize = uint64(stat.Blksize) fi.Blksize = uint64(stat.Blksize)
dir.Blocks = uint64(stat.Blocks) fi.Blocks = uint64(stat.Blocks)
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec)) fi.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec))
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec)) fi.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec))
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec)) fi.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec))
for i := len(name) - 1; i >= 0; i-- { for i := len(name) - 1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:] name = name[i+1:]
break break
} }
} }
dir.Name = name fi.Name = name
if isSymlink(lstat) && !isSymlink(stat) { if isSymlink(lstat) && !isSymlink(stat) {
dir.FollowedSymlink = true fi.FollowedSymlink = true
} }
return dir return fi
} }

View File

@ -10,29 +10,29 @@ func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
dir.Dev = stat.Dev fi.Dev = stat.Dev
dir.Ino = uint64(stat.Ino) fi.Ino = uint64(stat.Ino)
dir.Nlink = uint64(stat.Nlink) fi.Nlink = uint64(stat.Nlink)
dir.Mode = stat.Mode fi.Mode = stat.Mode
dir.Uid = stat.Uid fi.Uid = stat.Uid
dir.Gid = stat.Gid fi.Gid = stat.Gid
dir.Rdev = stat.Rdev fi.Rdev = stat.Rdev
dir.Size = uint64(stat.Size) fi.Size = uint64(stat.Size)
dir.Blksize = uint64(stat.Blksize) fi.Blksize = uint64(stat.Blksize)
dir.Blocks = uint64(stat.Blocks) fi.Blocks = uint64(stat.Blocks)
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim)) fi.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim))
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim)) fi.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim))
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim)) fi.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim))
for i := len(name) - 1; i >= 0; i-- { for i := len(name) - 1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:] name = name[i+1:]
break break
} }
} }
dir.Name = name fi.Name = name
if isSymlink(lstat) && !isSymlink(stat) { if isSymlink(lstat) && !isSymlink(stat) {
dir.FollowedSymlink = true fi.FollowedSymlink = true
} }
return dir return fi
} }

View File

@ -10,6 +10,6 @@ func isSymlink(stat *syscall.Stat_t) bool {
panic("windows isSymlink not implemented") panic("windows isSymlink not implemented")
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
panic("windows dirFromStat not implemented") panic("windows fileInfoFromStat not implemented")
} }

View File

@ -10,29 +10,29 @@ func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
dir.Dev = uint64(stat.Dev) fi.Dev = uint64(stat.Dev)
dir.Ino = uint64(stat.Ino) fi.Ino = uint64(stat.Ino)
dir.Nlink = uint64(stat.Nlink) fi.Nlink = uint64(stat.Nlink)
dir.Mode = stat.Mode fi.Mode = stat.Mode
dir.Uid = stat.Uid fi.Uid = stat.Uid
dir.Gid = stat.Gid fi.Gid = stat.Gid
dir.Rdev = uint64(stat.Rdev) fi.Rdev = uint64(stat.Rdev)
dir.Size = uint64(stat.Size) fi.Size = uint64(stat.Size)
dir.Blksize = uint64(stat.Blksize) fi.Blksize = uint64(stat.Blksize)
dir.Blocks = uint64(stat.Blocks) fi.Blocks = uint64(stat.Blocks)
dir.Atime_ns = uint64(stat.Atime) * 1e9 fi.Atime_ns = uint64(stat.Atime) * 1e9
dir.Mtime_ns = uint64(stat.Mtime) * 1e9 fi.Mtime_ns = uint64(stat.Mtime) * 1e9
dir.Ctime_ns = uint64(stat.Ctime) * 1e9 fi.Ctime_ns = uint64(stat.Ctime) * 1e9
for i := len(name) - 1; i >= 0; i-- { for i := len(name) - 1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:] name = name[i+1:]
break break
} }
} }
dir.Name = name fi.Name = name
if isSymlink(lstat) && !isSymlink(stat) { if isSymlink(lstat) && !isSymlink(stat) {
dir.FollowedSymlink = true fi.FollowedSymlink = true
} }
return dir return fi
} }

View File

@ -12,8 +12,8 @@ import "syscall"
// Getpagesize returns the underlying system's memory page size. // Getpagesize returns the underlying system's memory page size.
func Getpagesize() int { return syscall.Getpagesize() } func Getpagesize() int { return syscall.Getpagesize() }
// A Dir describes a file and is returned by Stat, Fstat, and Lstat // A FileInfo describes a file and is returned by Stat, Fstat, and Lstat
type Dir struct { type FileInfo struct {
Dev uint64 // device number of file system holding file. Dev uint64 // device number of file system holding file.
Ino uint64 // inode number. Ino uint64 // inode number.
Nlink uint64 // number of hard links. Nlink uint64 // number of hard links.
@ -31,26 +31,26 @@ type Dir struct {
FollowedSymlink bool // followed a symlink to get this information FollowedSymlink bool // followed a symlink to get this information
} }
// IsFifo reports whether the Dir describes a FIFO file. // IsFifo reports whether the FileInfo describes a FIFO file.
func (dir *Dir) IsFifo() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO } func (f *FileInfo) IsFifo() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFIFO }
// IsChar reports whether the Dir describes a character special file. // IsChar reports whether the FileInfo describes a character special file.
func (dir *Dir) IsChar() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR } func (f *FileInfo) IsChar() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFCHR }
// IsDirectory reports whether the Dir describes a directory. // IsDirectory reports whether the FileInfo describes a directory.
func (dir *Dir) IsDirectory() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR } func (f *FileInfo) IsDirectory() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFDIR }
// IsBlock reports whether the Dir describes a block special file. // IsBlock reports whether the FileInfo describes a block special file.
func (dir *Dir) IsBlock() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK } func (f *FileInfo) IsBlock() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFBLK }
// IsRegular reports whether the Dir describes a regular file. // IsRegular reports whether the FileInfo describes a regular file.
func (dir *Dir) IsRegular() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG } func (f *FileInfo) IsRegular() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFREG }
// IsSymlink reports whether the Dir describes a symbolic link. // IsSymlink reports whether the FileInfo describes a symbolic link.
func (dir *Dir) IsSymlink() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK } func (f *FileInfo) IsSymlink() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFLNK }
// IsSocket reports whether the Dir describes a socket. // IsSocket reports whether the FileInfo describes a socket.
func (dir *Dir) IsSocket() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK } func (f *FileInfo) IsSocket() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFSOCK }
// Permission returns the file permission bits. // Permission returns the file permission bits.
func (dir *Dir) Permission() int { return int(dir.Mode & 0777) } func (f *FileInfo) Permission() int { return int(f.Mode & 0777) }

View File

@ -143,17 +143,17 @@ func Ext(path string) string {
// visited by Walk. The parameter path is the full path of d relative // visited by Walk. The parameter path is the full path of d relative
// to root. // to root.
type Visitor interface { type Visitor interface {
VisitDir(path string, d *os.Dir) bool VisitDir(path string, f *os.FileInfo) bool
VisitFile(path string, d *os.Dir) VisitFile(path string, f *os.FileInfo)
} }
func walk(path string, d *os.Dir, v Visitor, errors chan<- os.Error) { func walk(path string, f *os.FileInfo, v Visitor, errors chan<- os.Error) {
if !d.IsDirectory() { if !f.IsDirectory() {
v.VisitFile(path, d) v.VisitFile(path, f)
return return
} }
if !v.VisitDir(path, d) { if !v.VisitDir(path, f) {
return // skip directory entries return // skip directory entries
} }
@ -177,12 +177,12 @@ func walk(path string, d *os.Dir, v Visitor, errors chan<- os.Error) {
// If errors != nil, Walk sends each directory read error // If errors != nil, Walk sends each directory read error
// to the channel. Otherwise Walk discards the error. // to the channel. Otherwise Walk discards the error.
func Walk(root string, v Visitor, errors chan<- os.Error) { func Walk(root string, v Visitor, errors chan<- os.Error) {
d, err := os.Lstat(root) f, err := os.Lstat(root)
if err != nil { if err != nil {
if errors != nil { if errors != nil {
errors <- err errors <- err
} }
return // can't progress return // can't progress
} }
walk(root, d, v, errors) walk(root, f, v, errors)
} }

View File

@ -224,13 +224,13 @@ func mark(name string) {
type TestVisitor struct{} type TestVisitor struct{}
func (v *TestVisitor) VisitDir(path string, d *os.Dir) bool { func (v *TestVisitor) VisitDir(path string, f *os.FileInfo) bool {
mark(d.Name) mark(f.Name)
return true return true
} }
func (v *TestVisitor) VisitFile(path string, d *os.Dir) { func (v *TestVisitor) VisitFile(path string, f *os.FileInfo) {
mark(d.Name) mark(f.Name)
} }
func TestWalk(t *testing.T) { func TestWalk(t *testing.T) {