diff options
author | Drew Richardson <drewrichardson@gmail.com> | 2021-04-01 17:05:24 -0700 |
---|---|---|
committer | Emmanuel Odeke <emmanuel@orijtech.com> | 2021-04-03 20:14:37 +0000 |
commit | 971c7154b04d8dd00da932a26ecb6bb8d8fc133d (patch) | |
tree | 51ad091c7ccbc9cf5fa300b9bbfde35ad02101b5 /src/io | |
parent | 6986c02d72db6806a46406ef398aa10f26018c20 (diff) | |
download | go-971c7154b04d8dd00da932a26ecb6bb8d8fc133d.tar.gz go-971c7154b04d8dd00da932a26ecb6bb8d8fc133d.zip |
io/fs: implement subFS.Sub
Calling fs.Sub with the result of fs.Sub multiple times creates a deep
call stack for Open and other methods. Enhance the fs.FS returned by
fs.Sub to implement fs.SubFS and reduce the call stack.
Fixes #45349
Change-Id: I10e10501e030176e10e2ae5ad260212e5c784bed
Reviewed-on: https://go-review.googlesource.com/c/go/+/306769
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/fs/sub.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/io/fs/sub.go b/src/io/fs/sub.go index d689b9e2bc..7822e555ea 100644 --- a/src/io/fs/sub.go +++ b/src/io/fs/sub.go @@ -125,3 +125,14 @@ func (f *subFS) Glob(pattern string) ([]string, error) { } return list, f.fixErr(err) } + +func (f *subFS) Sub(dir string) (FS, error) { + if dir == "." { + return f, nil + } + full, err := f.fullName("sub", dir) + if err != nil { + return nil, err + } + return &subFS{f.fsys, full}, nil +} |