Skip to content

Commit 9b64d74

Browse files
committed
Use functional options when constructing Symlink locator
Signed-off-by: Evan Lezar <[email protected]>
1 parent 99cc0ae commit 9b64d74

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ func (m command) run(c *cli.Context, cfg *config) error {
101101

102102
csvFiles := cfg.filenames.Value()
103103

104-
chainLocator := lookup.NewSymlinkChainLocator(m.logger, cfg.hostRoot)
104+
chainLocator := lookup.NewSymlinkChainLocator(
105+
lookup.WithLogger(m.logger),
106+
lookup.WithRoot(cfg.hostRoot),
107+
)
105108

106109
var candidates []string
107110
for _, file := range csvFiles {

internal/discover/csv.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string)
3333
return None{}, nil
3434
}
3535

36-
symlinkLocator := lookup.NewSymlinkLocator(logger, driverRoot)
36+
symlinkLocator := lookup.NewSymlinkLocator(
37+
lookup.WithLogger(logger),
38+
lookup.WithRoot(driverRoot),
39+
)
3740
locators := map[csv.MountSpecType]lookup.Locator{
3841
csv.MountSpecDev: lookup.NewCharDeviceLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)),
3942
csv.MountSpecDir: lookup.NewDirectoryLocator(logger, driverRoot),

internal/discover/symlinks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ func (d symlinkHook) getSpecificLinks() ([]string, error) {
113113
}
114114

115115
func (d symlinkHook) getCSVFileSymlinks() []string {
116-
chainLocator := lookup.NewSymlinkChainLocator(d.logger, d.driverRoot)
116+
chainLocator := lookup.NewSymlinkChainLocator(
117+
lookup.WithLogger(d.logger),
118+
lookup.WithRoot(d.driverRoot),
119+
)
117120

118121
var candidates []string
119122
for _, file := range d.csvFiles {

internal/lookup/library.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) {
4141

4242
l := library{
4343
logger: logger,
44-
symlink: NewSymlinkLocator(logger, root),
44+
symlink: NewSymlinkLocator(WithLogger(logger), WithRoot(root)),
4545
cache: cache,
4646
}
4747

internal/lookup/symlinks.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"path/filepath"
2222

23-
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2423
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
2524
)
2625

@@ -33,9 +32,8 @@ type symlink struct {
3332
}
3433

3534
// NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
36-
// A logger can also be specified.
37-
func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
38-
f := newFileLocator(WithLogger(logger), WithRoot(root))
35+
func NewSymlinkChainLocator(opts ...Option) Locator {
36+
f := newFileLocator(opts...)
3937
l := symlinkChain{
4038
file: *f,
4139
}
@@ -44,9 +42,8 @@ func NewSymlinkChainLocator(logger logger.Interface, root string) Locator {
4442
}
4543

4644
// NewSymlinkLocator creats a locator that can be used for locating files through symlinks.
47-
// A logger can also be specified.
48-
func NewSymlinkLocator(logger logger.Interface, root string) Locator {
49-
f := newFileLocator(WithLogger(logger), WithRoot(root))
45+
func NewSymlinkLocator(opts ...Option) Locator {
46+
f := newFileLocator(opts...)
5047
l := symlink{
5148
file: *f,
5249
}

0 commit comments

Comments
 (0)