diff options
author | Ian Lance Taylor <iant@golang.org> | 2023-05-01 17:38:08 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-05-04 16:27:35 +0000 |
commit | 1596aeec8ecc8f115bffad49a3d92944fc278f9a (patch) | |
tree | 3bb90b11f06add9b467d206abb8263e8dfe73d2c /src/archive | |
parent | 09a24a91b5aff200aa5fb8e75977c5a354702089 (diff) | |
download | go-1596aeec8ecc8f115bffad49a3d92944fc278f9a.tar.gz go-1596aeec8ecc8f115bffad49a3d92944fc278f9a.zip |
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/archive')
-rw-r--r-- | src/archive/tar/common.go | 4 | ||||
-rw-r--r-- | src/archive/zip/reader.go | 4 | ||||
-rw-r--r-- | src/archive/zip/struct.go | 4 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/archive/tar/common.go b/src/archive/tar/common.go index 38216ac13f..dc9d350eb7 100644 --- a/src/archive/tar/common.go +++ b/src/archive/tar/common.go @@ -607,6 +607,10 @@ func (fi headerFileInfo) Mode() (mode fs.FileMode) { return mode } +func (fi headerFileInfo) String() string { + return fs.FormatFileInfo(fi) +} + // sysStat, if non-nil, populates h from system-dependent fields of fi. var sysStat func(fi fs.FileInfo, h *Header) error diff --git a/src/archive/zip/reader.go b/src/archive/zip/reader.go index c0e8d97e4e..1fde1decc4 100644 --- a/src/archive/zip/reader.go +++ b/src/archive/zip/reader.go @@ -780,6 +780,10 @@ func (f *fileListEntry) ModTime() time.Time { func (f *fileListEntry) Info() (fs.FileInfo, error) { return f, nil } +func (f *fileListEntry) String() string { + return fs.FormatDirEntry(f) +} + // toValidName coerces name to be a valid name for fs.FS.Open. func toValidName(name string) string { name = strings.ReplaceAll(name, `\`, `/`) diff --git a/src/archive/zip/struct.go b/src/archive/zip/struct.go index 25ce6f5411..9a8e67cc69 100644 --- a/src/archive/zip/struct.go +++ b/src/archive/zip/struct.go @@ -190,6 +190,10 @@ func (fi headerFileInfo) Sys() any { return fi.fh } func (fi headerFileInfo) Info() (fs.FileInfo, error) { return fi, nil } +func (fi headerFileInfo) String() string { + return fs.FormatFileInfo(fi) +} + // FileInfoHeader creates a partially-populated FileHeader from an // fs.FileInfo. // Because fs.FileInfo's Name method returns only the base name of |