Use getSearchPrefixes for all locators

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-11-25 14:19:07 +01:00
parent d1a3de7671
commit db962c4bf2
4 changed files with 5 additions and 11 deletions

View File

@ -19,7 +19,6 @@ package lookup
import (
"fmt"
"os"
"path/filepath"
"github.com/sirupsen/logrus"
)
@ -33,7 +32,7 @@ const (
func NewCharDeviceLocator(logger *logrus.Logger, root string) Locator {
l := file{
logger: logger,
prefixes: []string{root, filepath.Join(root, devRoot)},
prefixes: getSearchPrefixes(root, "", devRoot),
filter: assertCharDevice,
}

View File

@ -28,7 +28,7 @@ import (
func NewDirectoryLocator(logger *log.Logger, root string) Locator {
l := file{
logger: logger,
prefixes: []string{root},
prefixes: getSearchPrefixes(root),
filter: assertDirectory,
}

View File

@ -19,7 +19,6 @@ package lookup
import (
"fmt"
"os"
"path/filepath"
"strings"
log "github.com/sirupsen/logrus"
@ -37,14 +36,10 @@ func NewExecutableLocator(logger *log.Logger, root string) Locator {
}
func newExecutableLocator(logger *log.Logger, root string, paths ...string) *executable {
var prefixes []string
for _, dir := range paths {
prefixes = append(prefixes, filepath.Join(root, dir))
}
l := executable{
file: file{
logger: logger,
prefixes: prefixes,
prefixes: getSearchPrefixes(root, paths...),
filter: assertExecutable,
},
}

View File

@ -34,7 +34,7 @@ func TestExecutableLocator(t *testing.T) {
}{
{
root: "",
expectedPrefixes: nil,
expectedPrefixes: []string{""},
},
{
root: "",
@ -48,7 +48,7 @@ func TestExecutableLocator(t *testing.T) {
},
{
root: "/",
expectedPrefixes: nil,
expectedPrefixes: []string{"/"},
},
{
root: "/",