From: mstmdev Date: Tue, 12 Sep 2023 11:49:41 +0000 (+0000) Subject: io/fs, path/filepath, cmd/gofmt: replace statDirEntry with fs.FileInfoToDirEntry X-Git-Tag: go1.22rc1~874 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5f04ef752bc9485821eae8a5b248b9d39d57989c;p=gostls13.git io/fs, path/filepath, cmd/gofmt: replace statDirEntry with fs.FileInfoToDirEntry Change-Id: Ie914367314ca72fab34c4d4529755dea853cf325 GitHub-Last-Rev: bc61665d33d7f15da371dcfb90c132fab25fc233 GitHub-Pull-Request: golang/go#62342 Reviewed-on: https://go-review.googlesource.com/c/go/+/523876 Reviewed-by: Ian Lance Taylor Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Tobias Klauser Auto-Submit: Ian Lance Taylor Commit-Queue: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Heschi Kreinick Reviewed-by: Daniel Martí --- diff --git a/src/cmd/gofmt/long_test.go b/src/cmd/gofmt/long_test.go index 8db348a50f..21a01196cf 100644 --- a/src/cmd/gofmt/long_test.go +++ b/src/cmd/gofmt/long_test.go @@ -126,7 +126,7 @@ func genFilenames(t *testing.T, filenames chan<- string) { if *files != "" { for _, filename := range strings.Split(*files, ",") { fi, err := os.Stat(filename) - handleFile(filename, &statDirEntry{fi}, err) + handleFile(filename, fs.FileInfoToDirEntry(fi), err) } return // ignore files under -root } @@ -170,16 +170,3 @@ func TestAll(t *testing.T) { fmt.Printf("processed %d files\n", nfiles) } } - -type statDirEntry struct { - info fs.FileInfo -} - -func (d *statDirEntry) Name() string { return d.info.Name() } -func (d *statDirEntry) IsDir() bool { return d.info.IsDir() } -func (d *statDirEntry) Type() fs.FileMode { return d.info.Mode().Type() } -func (d *statDirEntry) Info() (fs.FileInfo, error) { return d.info, nil } - -func (d *statDirEntry) String() string { - return fs.FormatDirEntry(d) -} diff --git a/src/io/fs/walk.go b/src/io/fs/walk.go index baf559ebca..eb98568cda 100644 --- a/src/io/fs/walk.go +++ b/src/io/fs/walk.go @@ -119,23 +119,10 @@ func WalkDir(fsys FS, root string, fn WalkDirFunc) error { if err != nil { err = fn(root, nil, err) } else { - err = walkDir(fsys, root, &statDirEntry{info}, fn) + err = walkDir(fsys, root, FileInfoToDirEntry(info), fn) } if err == SkipDir || err == SkipAll { return nil } return err } - -type statDirEntry struct { - info FileInfo -} - -func (d *statDirEntry) Name() string { return d.info.Name() } -func (d *statDirEntry) IsDir() bool { return d.info.IsDir() } -func (d *statDirEntry) Type() FileMode { return d.info.Mode().Type() } -func (d *statDirEntry) Info() (FileInfo, error) { return d.info, nil } - -func (d *statDirEntry) String() string { - return FormatDirEntry(d) -} diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 41fa733af9..6dcb0e1fb9 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -545,7 +545,7 @@ func WalkDir(root string, fn fs.WalkDirFunc) error { if err != nil { err = fn(root, nil, err) } else { - err = walkDir(root, &statDirEntry{info}, fn) + err = walkDir(root, fs.FileInfoToDirEntry(info), fn) } if err == SkipDir || err == SkipAll { return nil @@ -553,19 +553,6 @@ func WalkDir(root string, fn fs.WalkDirFunc) error { return err } -type statDirEntry struct { - info fs.FileInfo -} - -func (d *statDirEntry) Name() string { return d.info.Name() } -func (d *statDirEntry) IsDir() bool { return d.info.IsDir() } -func (d *statDirEntry) Type() fs.FileMode { return d.info.Mode().Type() } -func (d *statDirEntry) Info() (fs.FileInfo, error) { return d.info, nil } - -func (d *statDirEntry) String() string { - return fs.FormatDirEntry(d) -} - // Walk walks the file tree rooted at root, calling fn for each file or // directory in the tree, including root. // diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 621208d31e..51e6a20554 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -560,25 +560,12 @@ func tempDirCanonical(t *testing.T) string { func TestWalk(t *testing.T) { walk := func(root string, fn fs.WalkDirFunc) error { return filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { - return fn(path, &statDirEntry{info}, err) + return fn(path, fs.FileInfoToDirEntry(info), err) }) } testWalk(t, walk, 1) } -type statDirEntry struct { - info fs.FileInfo -} - -func (d *statDirEntry) Name() string { return d.info.Name() } -func (d *statDirEntry) IsDir() bool { return d.info.IsDir() } -func (d *statDirEntry) Type() fs.FileMode { return d.info.Mode().Type() } -func (d *statDirEntry) Info() (fs.FileInfo, error) { return d.info, nil } - -func (d *statDirEntry) String() string { - return fs.FormatDirEntry(d) -} - func TestWalkDir(t *testing.T) { testWalk(t, filepath.WalkDir, 2) }