]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: add String for fs.{FileInfo,DirEntry} implementations
authorIan Lance Taylor <iant@golang.org>
Tue, 2 May 2023 00:38:08 +0000 (17:38 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 4 May 2023 16:27:35 +0000 (16:27 +0000)
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>
18 files changed:
src/archive/tar/common.go
src/archive/zip/reader.go
src/archive/zip/struct.go
src/cmd/distpack/archive.go
src/cmd/go/internal/fsys/fsys.go
src/cmd/go/internal/modfetch/coderepo.go
src/cmd/gofmt/long_test.go
src/cmd/pack/pack_test.go
src/embed/embed.go
src/io/fs/readdir.go
src/io/fs/walk.go
src/net/http/fs_test.go
src/os/dir_plan9.go
src/os/dir_windows.go
src/os/file_unix.go
src/path/filepath/path.go
src/path/filepath/path_test.go
src/testing/fstest/mapfs.go

index 38216ac13fdf79507941ea981ec27bc36075ed2f..dc9d350eb72791ad7af299bea379f2794e8cda77 100644 (file)
@@ -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
 
index c0e8d97e4ec57d95b5956c77223c4621dcff03dd..1fde1decc4b3aa74f6c167fe7c6c069e4089f231 100644 (file)
@@ -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, `\`, `/`)
index 25ce6f5411695e9e89d1d16a0ae1e10efeb6a9e8..9a8e67cc69488915490f66259ec8e839e62b8045 100644 (file)
@@ -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
index 2fdc006b55981b48aa06d238ce958b68521d7ca0..730233765c22d13986140c3f9af1e439940bf0c0 100644 (file)
@@ -48,6 +48,10 @@ func (i fileInfo) IsDir() bool        { return false }
 func (i fileInfo) Size() int64        { return i.f.Size }
 func (i fileInfo) Sys() any           { return nil }
 
+func (i fileInfo) String() string {
+       return fs.FormatFileInfo(i)
+}
+
 // NewArchive returns a new Archive containing all the files in the directory dir.
 // The archive can be amended afterward using methods like Add and Filter.
 func NewArchive(dir string) (*Archive, error) {
index c371610a4d896af69e60adbae41cf772a2baa850..b83c5a3202b70cef6b4e2af52d10cd3c749c7adc 100644 (file)
@@ -583,6 +583,10 @@ func (f fakeFile) ModTime() time.Time { return f.real.ModTime() }
 func (f fakeFile) IsDir() bool        { return f.real.IsDir() }
 func (f fakeFile) Sys() any           { return f.real.Sys() }
 
+func (f fakeFile) String() string {
+       return fs.FormatFileInfo(f)
+}
+
 // missingFile provides an fs.FileInfo for an overlaid file where the
 // destination file in the overlay doesn't exist. It returns zero values
 // for the fileInfo methods other than Name, set to the file's name, and Mode
@@ -596,6 +600,10 @@ func (f missingFile) ModTime() time.Time { return time.Unix(0, 0) }
 func (f missingFile) IsDir() bool        { return false }
 func (f missingFile) Sys() any           { return nil }
 
+func (f missingFile) String() string {
+       return fs.FormatFileInfo(f)
+}
+
 // fakeDir provides an fs.FileInfo implementation for directories that are
 // implicitly created by overlaid files. Each directory in the
 // path of an overlaid file is considered to exist in the overlay filesystem.
@@ -608,6 +616,10 @@ func (f fakeDir) ModTime() time.Time { return time.Unix(0, 0) }
 func (f fakeDir) IsDir() bool        { return true }
 func (f fakeDir) Sys() any           { return nil }
 
+func (f fakeDir) String() string {
+       return fs.FormatFileInfo(f)
+}
+
 // Glob is like filepath.Glob but uses the overlay file system.
 func Glob(pattern string) (matches []string, err error) {
        Trace("Glob", pattern)
index 047bd71a6223f6b9cd7158620437dfdc8d91ae6b..002efcc517a9a38bebed1ceb809648dc0dd66f5d 100644 (file)
@@ -1155,6 +1155,10 @@ func (fi dataFileInfo) ModTime() time.Time { return time.Time{} }
 func (fi dataFileInfo) IsDir() bool        { return false }
 func (fi dataFileInfo) Sys() any           { return nil }
 
+func (fi dataFileInfo) String() string {
+       return fs.FormatFileInfo(fi)
+}
+
 // hasPathPrefix reports whether the path s begins with the
 // elements in prefix.
 func hasPathPrefix(s, prefix string) bool {
index 2ee5174b96f7c12da4f22cfa1da2d0b5bdda5c89..8db348a50f67982f6c8690e7a978c843c5429944 100644 (file)
@@ -179,3 +179,7 @@ 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)
+}
index 309139aa4dd8e6c18de4846f392f8be5d68a65f4..c3a63424dd9d26f2eaaf07c8f09c90684b6d8fc9 100644 (file)
@@ -497,6 +497,10 @@ func (f *FakeFile) Sys() any {
        return nil
 }
 
+func (f *FakeFile) String() string {
+       return fs.FormatFileInfo(f)
+}
+
 // Special helpers.
 
 func (f *FakeFile) Entry() *archive.Entry {
index 66934a89744502c6ebb0e0f1728984bdefcfa09a..8d155ebd55c59f1a21a21f79c27dbd5bc27e9ff2 100644 (file)
@@ -243,6 +243,10 @@ func (f *file) Mode() fs.FileMode {
        return 0444
 }
 
+func (f *file) String() string {
+       return fs.FormatFileInfo(f)
+}
+
 // dotFile is a file for the root directory,
 // which is omitted from the files list in a FS.
 var dotFile = &file{name: "./"}
index 2b10ddb0a3f407dd5c08387f1d8d1902d5eeace1..42aca49516986393d0d580d65ea5a6bbc848349d 100644 (file)
@@ -67,6 +67,10 @@ func (di dirInfo) Name() string {
        return di.fileInfo.Name()
 }
 
+func (di dirInfo) String() string {
+       return FormatDirEntry(di)
+}
+
 // FileInfoToDirEntry returns a DirEntry that returns information from info.
 // If info is nil, FileInfoToDirEntry returns nil.
 func FileInfoToDirEntry(info FileInfo) DirEntry {
index cff26104f047caed9b7d08dba33c9010dcff79eb..baf559ebcab0ae2ec131a022955083168f12990f 100644 (file)
@@ -135,3 +135,7 @@ 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)
+}
index 3f0f864b196ae4f2bc3a0c738bfed9540e8e247d..e37e0f04c9bf0cd9ea5abe2226f83c8691f125b9 100644 (file)
@@ -768,6 +768,10 @@ func (f *fakeFileInfo) Mode() fs.FileMode {
        return 0644
 }
 
+func (f *fakeFileInfo) String() string {
+       return fs.FormatFileInfo(f)
+}
+
 type fakeFile struct {
        io.ReadSeeker
        fi     *fakeFileInfo
index 8f6b0d61098e4e4f65bcc22387d378dcd934d688..6ea5940e71df9fb58b6ce61fba086663cd33e60d 100644 (file)
@@ -6,6 +6,7 @@ package os
 
 import (
        "io"
+       "io/fs"
        "syscall"
 )
 
@@ -79,3 +80,7 @@ func (de dirEntry) Name() string            { return de.fs.Name() }
 func (de dirEntry) IsDir() bool             { return de.fs.IsDir() }
 func (de dirEntry) Type() FileMode          { return de.fs.Mode().Type() }
 func (de dirEntry) Info() (FileInfo, error) { return de.fs, nil }
+
+func (de dirEntry) String() string {
+       return fs.FormatDirEntry(de)
+}
index ab120546c0a978bd9c768fb6ba97cd75863d6c5a..cee05cc7292857296c5053456880e7339e635a4c 100644 (file)
@@ -7,6 +7,7 @@ package os
 import (
        "internal/syscall/windows"
        "io"
+       "io/fs"
        "runtime"
        "sync"
        "syscall"
@@ -140,3 +141,7 @@ func (de dirEntry) Name() string            { return de.fs.Name() }
 func (de dirEntry) IsDir() bool             { return de.fs.IsDir() }
 func (de dirEntry) Type() FileMode          { return de.fs.Mode().Type() }
 func (de dirEntry) Info() (FileInfo, error) { return de.fs, nil }
+
+func (de dirEntry) String() string {
+       return fs.FormatDirEntry(de)
+}
index 4962e9077d2c0bb7dff4df7da1b11a14570195b1..a14295cfff78c1cde0aa845408d5446a5e73e644 100644 (file)
@@ -9,6 +9,7 @@ package os
 import (
        "internal/poll"
        "internal/syscall/unix"
+       "io/fs"
        "runtime"
        "syscall"
 )
@@ -432,6 +433,10 @@ func (d *unixDirent) Info() (FileInfo, error) {
        return lstat(d.parent + "/" + d.name)
 }
 
+func (d *unixDirent) String() string {
+       return fs.FormatDirEntry(d)
+}
+
 func newUnixDirent(parent, name string, typ FileMode) (DirEntry, error) {
        ude := &unixDirent{
                parent: parent,
index 8382ad5f3b3102fa5f094eccd798f156966dad9b..9772de4342d3e450d775661bbe590442bdec37b4 100644 (file)
@@ -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.
 //
index 0c73e288e5c1e08d627614093ae3ead504b69a37..469a107d147acb8904cc18e52ba60664e9d23ee5 100644 (file)
@@ -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)
 }
index 4595b7313db9dd9d1e3f7445b3427f107f1b3b17..a0b1f65668f532c7e8e8fb33a95097a153b88590 100644 (file)
@@ -159,6 +159,10 @@ func (i *mapFileInfo) IsDir() bool                { return i.f.Mode&fs.ModeDir !
 func (i *mapFileInfo) Sys() any                   { return i.f.Sys }
 func (i *mapFileInfo) Info() (fs.FileInfo, error) { return i, nil }
 
+func (i *mapFileInfo) String() string {
+       return fs.FormatFileInfo(i)
+}
+
 // An openMapFile is a regular (non-directory) fs.File open for reading.
 type openMapFile struct {
        path string