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{
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,

View File

@ -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"},
)

View File

@ -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),
)...,
)
}