From ec2b30c1e7630c722b632a07b5ae827997e392d7 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 11 Sep 2023 18:36:46 +0000 Subject: [PATCH] cluster: add DirFS() using hackpadfs/os Signed-off-by: Alejandro Mery --- pkg/cluster/cluster_fs.go | 25 +++++++++++++++++++++++++ pkg/cluster/cluster_scan_options.go | 3 +-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pkg/cluster/cluster_fs.go diff --git a/pkg/cluster/cluster_fs.go b/pkg/cluster/cluster_fs.go new file mode 100644 index 0000000..344eccb --- /dev/null +++ b/pkg/cluster/cluster_fs.go @@ -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 +} diff --git a/pkg/cluster/cluster_scan_options.go b/pkg/cluster/cluster_scan_options.go index 53d2a28..6a4b651 100644 --- a/pkg/cluster/cluster_scan_options.go +++ b/pkg/cluster/cluster_scan_options.go @@ -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 }