(name string)
| 878 | } |
| 879 | |
| 880 | func (fs defaultFS) Open(name string) (fs.File, error) { |
| 881 | // fs.FS.Open() already assumes that file names are relative to FS root path and considers name with prefix `/` as invalid |
| 882 | // For example `f.Name()` returns file names as absolute paths (e.g. `/tmp/data.csv`) so in case user wants to open |
| 883 | // a file with an absolute path we need to remove prefix and then call fs.FS.Open(). |
| 884 | // not to force users to cut prefix from file name we do it here. |
| 885 | if filepath.IsAbs(name) { |
| 886 | if strings.HasPrefix(name, fs.prefix) { |
| 887 | name = name[len(fs.prefix):] |
| 888 | if len(name) > 1 && os.IsPathSeparator(name[0]) { |
| 889 | name = name[1:] |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | return fs.fs.Open(name) |
| 894 | } |
| 895 | |
| 896 | func subFS(currentFs fs.FS, root string) (fs.FS, error) { |
| 897 | root = filepath.ToSlash(filepath.Clean(root)) // note: fs.FS operates only with slashes. `ToSlash` is necessary for Windows |
no outgoing calls