Use functional options when constructing direcory locator

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-07-18 15:36:03 +02:00
parent 9b64d74f6a
commit ce7d5f7a51
3 changed files with 8 additions and 10 deletions

View File

@ -39,7 +39,7 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string)
) )
locators := map[csv.MountSpecType]lookup.Locator{ locators := map[csv.MountSpecType]lookup.Locator{
csv.MountSpecDev: lookup.NewCharDeviceLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)), 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 // Libraries and symlinks are handled in the same way
csv.MountSpecLib: symlinkLocator, csv.MountSpecLib: symlinkLocator,
csv.MountSpecSym: symlinkLocator, csv.MountSpecSym: symlinkLocator,

View File

@ -38,7 +38,7 @@ func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) {
udev := NewMounts( udev := NewMounts(
logger, logger,
lookup.NewDirectoryLocator(logger, root), lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(root)),
root, root,
[]string{"/run/udev"}, []string{"/run/udev"},
) )

View File

@ -19,17 +19,15 @@ package lookup
import ( import (
"fmt" "fmt"
"os" "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 // NewDirectoryLocator creates a Locator that can be used to find directories at the specified root.
// is also specified. func NewDirectoryLocator(opts ...Option) Locator {
func NewDirectoryLocator(logger logger.Interface, root string) Locator {
return NewFileLocator( return NewFileLocator(
WithLogger(logger), append(
WithRoot(root), opts,
WithFilter(assertDirectory), WithFilter(assertDirectory),
)...,
) )
} }