c9f3e7a639
ADDED: * stringsx: ** RunesInString ** RuneMapFromString ** SquashConsec ** SquashConsecRunes ** SquashConsecRunesAll ** SquashMap ** SquashWhitespace
53 lines
925 B
Go
53 lines
925 B
Go
package main
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"r00t2.io/sysutils/paths"
|
|
)
|
|
|
|
// Open opens file fnm.
|
|
func (r *realFsMember) Open(fnm string) (fh fs.File, err error) {
|
|
|
|
if fh, err = r.Root.Open(fnm); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// ReadDir returns directory entries at fpath joined with the realFsMember's root.
|
|
func (r *realFsMember) ReadDir(fpath string) (entries []fs.DirEntry, err error) {
|
|
|
|
var rel string
|
|
var fsp string = fpath
|
|
|
|
if !filepath.IsAbs(fsp) {
|
|
fsp = filepath.Join(
|
|
r.Root.Name(),
|
|
filepath.FromSlash(fsp),
|
|
)
|
|
}
|
|
if err = paths.RealPath(&fsp); err != nil {
|
|
return
|
|
}
|
|
if rel, err = filepath.Rel(r.Root.Name(), fsp); err != nil {
|
|
// Not relative to this root, so skip.
|
|
err = nil
|
|
return
|
|
}
|
|
if strings.HasPrefix(rel, "..") {
|
|
// Absolute but not relative to this root, so skip.
|
|
return
|
|
}
|
|
|
|
if entries, err = os.ReadDir(fsp); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|