Sub returns an FS corresponding to the subtree rooted at fsys's dir. If fs implements SubFS, Sub calls returns fsys.Sub(dir). Otherwise, if dir is ".", Sub returns fsys unchanged. Otherwise, Sub returns a new FS implementation sub that, in effect, implements sub.Open(dir) as fsys.Open(path.Join(dir, name)). The implementation also translates calls to ReadDir, ReadFile, and Glob appropriately. Note that Sub(os.DirFS("/"), "prefix") is equivalent to os.DirFS("/prefix") and that neither of them guarantees to avoid operating system accesses outside "/prefix", because the implementation of os.DirFS does not check for symbolic links inside "/prefix" that point to other directories. That is, os.DirFS is not a general substitute for a chroot-style security mechanism, and Sub does not change that fact.
if , := path.Match(, ""); != nil {
returnnil,
}
if == "." {
return []string{"."}, nil
}
:= .dir + "/" +
, := Glob(.fsys, )
for , := range {
, := .shorten()
if ! {
returnnil, errors.New("invalid result from inner fsys Glob: " + + " not in " + .dir) // can't use fmt in this package
}
[] =
}
return , .fixErr()
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.