]> Cypherpunks repositories - gostls13.git/commitdiff
io/fs: implement subFS.Sub
authorDrew Richardson <drewrichardson@gmail.com>
Fri, 2 Apr 2021 00:05:24 +0000 (17:05 -0700)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Sat, 3 Apr 2021 20:14:37 +0000 (20:14 +0000)
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>

src/io/fs/sub.go

index d689b9e2bcfb3a82fe30235210d0bc9966388a86..7822e555eaa0eb35ebeba07f4b669c9696aa4829 100644 (file)
@@ -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
+}