mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 21:39:10 +00:00
introduce resolveSelected helper
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
3537d76726
commit
881b1c0e08
@ -237,22 +237,8 @@ func (c *ldcache) getEntries(selected func(string) bool) []entry {
|
|||||||
// The 32-bit and 64-bit libraries are returned separately.
|
// The 32-bit and 64-bit libraries are returned separately.
|
||||||
func (c *ldcache) List() ([]string, []string) {
|
func (c *ldcache) List() ([]string, []string) {
|
||||||
all := func(s string) bool { return true }
|
all := func(s string) bool { return true }
|
||||||
paths := make(map[int][]string)
|
|
||||||
processed := make(map[string]bool)
|
|
||||||
for _, e := range c.getEntries(all) {
|
|
||||||
path, err := c.resolve(e.value)
|
|
||||||
if err != nil {
|
|
||||||
c.logger.Debugf("Could not resolve entry: %v", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if processed[path] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
paths[e.bits] = append(paths[e.bits], path)
|
|
||||||
processed[path] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return paths[32], paths[64]
|
return c.resolveSelected(all)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup searches the ldcache for the specified prefixes.
|
// Lookup searches the ldcache for the specified prefixes.
|
||||||
@ -260,9 +246,6 @@ func (c *ldcache) List() ([]string, []string) {
|
|||||||
func (c *ldcache) Lookup(libPrefixes ...string) ([]string, []string) {
|
func (c *ldcache) Lookup(libPrefixes ...string) ([]string, []string) {
|
||||||
c.logger.Debugf("Looking up %v in cache", libPrefixes)
|
c.logger.Debugf("Looking up %v in cache", libPrefixes)
|
||||||
|
|
||||||
paths := make(map[int][]string)
|
|
||||||
processed := make(map[string]bool)
|
|
||||||
|
|
||||||
// We define a functor to check whether a given library name matches any of the prefixes
|
// We define a functor to check whether a given library name matches any of the prefixes
|
||||||
matchesAnyPrefix := func(s string) bool {
|
matchesAnyPrefix := func(s string) bool {
|
||||||
for _, p := range libPrefixes {
|
for _, p := range libPrefixes {
|
||||||
@ -273,10 +256,19 @@ func (c *ldcache) Lookup(libPrefixes ...string) ([]string, []string) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range c.getEntries(matchesAnyPrefix) {
|
return c.resolveSelected(matchesAnyPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolveSelected process the entries in the LDCach based on the supplied filter and returns the resolved paths.
|
||||||
|
// The paths are separated by bittage.
|
||||||
|
func (c *ldcache) resolveSelected(selected func(string) bool) ([]string, []string) {
|
||||||
|
paths := make(map[int][]string)
|
||||||
|
processed := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, e := range c.getEntries(selected) {
|
||||||
path, err := c.resolve(e.value)
|
path, err := c.resolve(e.value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Debug("Could not resolve entry: %v", err)
|
c.logger.Debugf("Could not resolve entry: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if processed[path] {
|
if processed[path] {
|
||||||
|
Loading…
Reference in New Issue
Block a user