v1.16.11
ADDED: * stringsx: ** RunesInString ** RuneMapFromString ** SquashConsec ** SquashConsecRunes ** SquashConsecRunesAll ** SquashMap ** SquashWhitespace
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user