ADDED:
* iox/fsx:
** FsPaths
** HasType
** IsType
This commit is contained in:
brent saner
2026-08-08 00:30:44 -04:00
parent 4e7d474fb3
commit 67bd30907e
3 changed files with 18 additions and 2 deletions
+16
View File
@@ -6,6 +6,8 @@ import (
"path/filepath"
)
// TODO: FilterFsPaths
/*
FsPaths returns all paths in [io/fs.FS] `fsys`.
@@ -82,6 +84,8 @@ func getEntries(fsys fs.FS, t fs.FileMode, inclFiles bool, maxDepth int, relPath
var idx int
var p string
var k string
var v fs.DirEntry
var e []fs.DirEntry
var subs map[string]fs.DirEntry = make(map[string]fs.DirEntry)
@@ -89,12 +93,24 @@ func getEntries(fsys fs.FS, t fs.FileMode, inclFiles bool, maxDepth int, relPath
return
}
fsPaths = make(map[string]fs.DirEntry)
for idx = range e {
p = filepath.Join(relPath, e[idx].Name())
if e[idx].IsDir() {
if subs, err = getEntries(fsys, t, inclFiles, maxDepth, p); err != nil {
return
}
for k, v = range subs {
fsPaths[k] = v
}
}
if t != 0 {
if HasType(t, e[idx].Type()) {
fsPaths[p] = e[idx]
}
} else if inclFiles && e[idx].Type() == 0 {
fsPaths[p] = e[idx]
}
}