From ce7d5f7a5170b92a7cf5228698228942636d5883 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 18 Jul 2023 15:36:03 +0200 Subject: [PATCH] Use functional options when constructing direcory locator Signed-off-by: Evan Lezar --- internal/discover/csv.go | 2 +- internal/discover/gds.go | 2 +- internal/lookup/dir.go | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/discover/csv.go b/internal/discover/csv.go index f5ffe61c..2d3b4018 100644 --- a/internal/discover/csv.go +++ b/internal/discover/csv.go @@ -39,7 +39,7 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string) ) locators := map[csv.MountSpecType]lookup.Locator{ csv.MountSpecDev: lookup.NewCharDeviceLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)), - csv.MountSpecDir: lookup.NewDirectoryLocator(logger, driverRoot), + csv.MountSpecDir: lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)), // Libraries and symlinks are handled in the same way csv.MountSpecLib: symlinkLocator, csv.MountSpecSym: symlinkLocator, diff --git a/internal/discover/gds.go b/internal/discover/gds.go index 01360d82..c0307f26 100644 --- a/internal/discover/gds.go +++ b/internal/discover/gds.go @@ -38,7 +38,7 @@ func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) { udev := NewMounts( logger, - lookup.NewDirectoryLocator(logger, root), + lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(root)), root, []string{"/run/udev"}, ) diff --git a/internal/lookup/dir.go b/internal/lookup/dir.go index cf6eeb0b..edf42b56 100644 --- a/internal/lookup/dir.go +++ b/internal/lookup/dir.go @@ -19,17 +19,15 @@ package lookup import ( "fmt" "os" - - "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) -// NewDirectoryLocator creates a Locator that can be used to find directories at the specified root. A logger -// is also specified. -func NewDirectoryLocator(logger logger.Interface, root string) Locator { +// NewDirectoryLocator creates a Locator that can be used to find directories at the specified root. +func NewDirectoryLocator(opts ...Option) Locator { return NewFileLocator( - WithLogger(logger), - WithRoot(root), - WithFilter(assertDirectory), + append( + opts, + WithFilter(assertDirectory), + )..., ) }