1
0
mirror of https://github.com/golang/go synced 2024-09-24 03:10:16 -06:00

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 <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
This commit is contained in:
Charlie Moog 2021-03-24 19:17:03 -05:00 committed by Ian Lance Taylor
parent d8306ee1f9
commit a25c584629

View File

@ -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