Skip to content

Commit bda6501

Browse files
committed
[no-relnote] Move ldcache locatore to separate file
Signed-off-by: Evan Lezar <[email protected]>
1 parent 6b5d470 commit bda6501

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

internal/lookup/library-ldcache.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
# Copyright 2024 NVIDIA CORPORATION
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
**/
16+
17+
package lookup
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache"
23+
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
24+
)
25+
26+
type ldcacheLocator struct {
27+
logger logger.Interface
28+
cache ldcache.LDCache
29+
}
30+
31+
var _ Locator = (*ldcacheLocator)(nil)
32+
33+
func newLdcacheLocator(opts ...Option) Locator {
34+
b := newBuilder(opts...)
35+
36+
cache, err := ldcache.New(b.logger, b.root)
37+
if err != nil {
38+
// If we failed to open the LDCache, we default to a symlink locator.
39+
b.logger.Warningf("Failed to load ldcache: %v", err)
40+
return nil
41+
}
42+
43+
return &ldcacheLocator{
44+
logger: b.logger,
45+
cache: cache,
46+
}
47+
}
48+
49+
// Locate finds the specified libraryname.
50+
// If the input is a library name, the ldcache is searched otherwise the
51+
// provided path is resolved as a symlink.
52+
func (l ldcacheLocator) Locate(libname string) ([]string, error) {
53+
paths32, paths64 := l.cache.Lookup(libname)
54+
if len(paths32) > 0 {
55+
l.logger.Warningf("Ignoring 32-bit libraries for %v: %v", libname, paths32)
56+
}
57+
58+
if len(paths64) == 0 {
59+
return nil, fmt.Errorf("64-bit library %v: %w", libname, ErrNotFound)
60+
}
61+
62+
return paths64, nil
63+
}

internal/lookup/library.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@
1616

1717
package lookup
1818

19-
import (
20-
"fmt"
21-
22-
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache"
23-
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
24-
)
25-
26-
type ldcacheLocator struct {
27-
logger logger.Interface
28-
cache ldcache.LDCache
29-
}
30-
31-
var _ Locator = (*ldcacheLocator)(nil)
32-
3319
// NewLibraryLocator creates a library locator using the specified options.
3420
func NewLibraryLocator(opts ...Option) Locator {
3521
b := newBuilder(opts...)
@@ -67,35 +53,3 @@ func NewLibraryLocator(opts ...Option) Locator {
6753
)
6854
return l
6955
}
70-
71-
func newLdcacheLocator(opts ...Option) Locator {
72-
b := newBuilder(opts...)
73-
74-
cache, err := ldcache.New(b.logger, b.root)
75-
if err != nil {
76-
// If we failed to open the LDCache, we default to a symlink locator.
77-
b.logger.Warningf("Failed to load ldcache: %v", err)
78-
return nil
79-
}
80-
81-
return &ldcacheLocator{
82-
logger: b.logger,
83-
cache: cache,
84-
}
85-
}
86-
87-
// Locate finds the specified libraryname.
88-
// If the input is a library name, the ldcache is searched otherwise the
89-
// provided path is resolved as a symlink.
90-
func (l ldcacheLocator) Locate(libname string) ([]string, error) {
91-
paths32, paths64 := l.cache.Lookup(libname)
92-
if len(paths32) > 0 {
93-
l.logger.Warningf("Ignoring 32-bit libraries for %v: %v", libname, paths32)
94-
}
95-
96-
if len(paths64) == 0 {
97-
return nil, fmt.Errorf("64-bit library %v: %w", libname, ErrNotFound)
98-
}
99-
100-
return paths64, nil
101-
}

0 commit comments

Comments
 (0)