Use functional options when constructing Symlink locator

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-07-18 11:57:26 +02:00
parent 99cc0aebd6
commit 9b64d74f6a
5 changed files with 17 additions and 11 deletions

View File

@ -101,7 +101,10 @@ func (m command) run(c *cli.Context, cfg *config) error {
csvFiles := cfg.filenames.Value()
chainLocator := lookup.NewSymlinkChainLocator(m.logger, cfg.hostRoot)
chainLocator := lookup.NewSymlinkChainLocator(
lookup.WithLogger(m.logger),
lookup.WithRoot(cfg.hostRoot),
)
var candidates []string
for _, file := range csvFiles {

View File

@ -33,7 +33,10 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string)
return None{}, nil
}
symlinkLocator := lookup.NewSymlinkLocator(logger, driverRoot)
symlinkLocator := lookup.NewSymlinkLocator(
lookup.WithLogger(logger),
lookup.WithRoot(driverRoot),
)
locators := map[csv.MountSpecType]lookup.Locator{
csv.MountSpecDev: lookup.NewCharDeviceLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)),
csv.MountSpecDir: lookup.NewDirectoryLocator(logger, driverRoot),

View File

@ -113,7 +113,10 @@ func (d symlinkHook) getSpecificLinks() ([]string, error) {
}
func (d symlinkHook) getCSVFileSymlinks() []string {
chainLocator := lookup.NewSymlinkChainLocator(d.logger, d.driverRoot)
chainLocator := lookup.NewSymlinkChainLocator(
lookup.WithLogger(d.logger),
lookup.WithRoot(d.driverRoot),
)
var candidates []string
for _, file := range d.csvFiles {

View File

@ -41,7 +41,7 @@ func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) {
l := library{
logger: logger,
symlink: NewSymlinkLocator(logger, root),
symlink: NewSymlinkLocator(WithLogger(logger), WithRoot(root)),
cache: cache,
}

View File

@ -20,7 +20,6 @@ import (
"fmt"
"path/filepath"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
)
@ -33,9 +32,8 @@ type symlink struct {
}
// NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
// A logger can also be specified.
func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
f := newFileLocator(WithLogger(logger), WithRoot(root))
func NewSymlinkChainLocator(opts ...Option) Locator {
f := newFileLocator(opts...)
l := symlinkChain{
file: *f,
}
@ -44,9 +42,8 @@ func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
}
// NewSymlinkLocator creats a locator that can be used for locating files through symlinks.
// A logger can also be specified.
func NewSymlinkLocator(logger logger.Interface, root string) Locator {
f := newFileLocator(WithLogger(logger), WithRoot(root))
func NewSymlinkLocator(opts ...Option) Locator {
f := newFileLocator(opts...)
l := symlink{
file: *f,
}