cluster: add DirFS() using hackpadfs/os
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/hack-pad/hackpadfs/os"
|
||||
)
|
||||
|
||||
// DirFS returns a file system (an [fs.FS]) for the tree
|
||||
// of files rooted at the directory dir.
|
||||
func DirFS(dir string) (fs.FS, error) {
|
||||
dir = filepath.Clean(dir)
|
||||
fullPath, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sub, err := os.NewFS().Sub(fullPath[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sub, nil
|
||||
}
|
||||
Reference in New Issue
Block a user