aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-05-01 17:38:08 -0700
committerGopher Robot <gobot@golang.org>2023-05-04 16:27:35 +0000
commit1596aeec8ecc8f115bffad49a3d92944fc278f9a (patch)
tree3bb90b11f06add9b467d206abb8263e8dfe73d2c /src/path/filepath
parent09a24a91b5aff200aa5fb8e75977c5a354702089 (diff)
downloadgo-1596aeec8ecc8f115bffad49a3d92944fc278f9a.tar.xz
all: add String for fs.{FileInfo,DirEntry} implementations
The new String methods use the new FormatFileInfo and FormatDirEntry functions. Fixes #54451 Change-Id: I414cdfc212ec3c316fb2734756d2117842a23631 Reviewed-on: https://go-review.googlesource.com/c/go/+/491175 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/path/filepath')
-rw-r--r--src/path/filepath/path.go4
-rw-r--r--src/path/filepath/path_test.go4
2 files changed, 8 insertions, 0 deletions
diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go
index 8382ad5f3b..9772de4342 100644
--- a/src/path/filepath/path.go
+++ b/src/path/filepath/path.go
@@ -553,6 +553,10 @@ 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 0c73e288e5..469a107d14 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -571,6 +571,10 @@ 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)
}