cluster: add DirFS() using hackpadfs/os

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-11 18:36:46 +00:00
parent 3de7fcb605
commit ec2b30c1e7
2 changed files with 26 additions and 2 deletions
+25
View File
@@ -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
}
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"darvaza.org/resolver"
"darvaza.org/slog"
"github.com/hack-pad/hackpadfs/os"
)
// A ScanOption pre-configures the Zones before scanning
@@ -101,7 +100,7 @@ func NewFromDirectory(dir, domain string, opts ...ScanOption) (*Cluster, error)
return nil, err
}
sub, err := os.NewFS().Sub(fullPath[1:])
sub, err := DirFS(dir)
if err != nil {
return nil, err
}