From: Charlie Moog Date: Thu, 25 Mar 2021 00:17:03 +0000 (-0500) Subject: os: implement fs.StatFS for os.DirFS X-Git-Tag: go1.17beta1~827 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a25c584629;p=gostls13.git os: implement fs.StatFS for os.DirFS Change-Id: I1d7382bf522aeda7148431b348f6ab9a162be097 Reviewed-on: https://go-review.googlesource.com/c/go/+/304531 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Robert Griesemer --- diff --git a/src/os/file.go b/src/os/file.go index ebeb0d0ac9..e717f171e7 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -651,6 +651,17 @@ func (dir dirFS) Open(name string) (fs.File, error) { return f, nil } +func (dir dirFS) Stat(name string) (fs.FileInfo, error) { + if !fs.ValidPath(name) || runtime.GOOS == "windows" && containsAny(name, `\:`) { + return nil, &PathError{Op: "stat", Path: name, Err: ErrInvalid} + } + f, err := Stat(string(dir) + "/" + name) + if err != nil { + return nil, err + } + return f, nil +} + // ReadFile reads the named file and returns the contents. // A successful call returns err == nil, not err == EOF. // Because ReadFile reads the whole file, it does not treat an EOF from Read