Skip to content

Commit 54aee23

Browse files
committed
Move resolution of LDConfig to utils package
Signed-off-by: Evan Lezar <[email protected]>
1 parent 1e7a07a commit 54aee23

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ import (
2020
"errors"
2121
"fmt"
2222
"path/filepath"
23-
"strings"
2423

2524
"github.com/urfave/cli/v2"
2625

2726
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/utils"
28-
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
2927
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
3028
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
3129
)
@@ -115,7 +113,7 @@ func (m command) run(c *cli.Context, cfg *options) error {
115113
return fmt.Errorf("failed to determined container root: %v", err)
116114
}
117115

118-
ldconfigPath := m.resolveLDConfigPath(cfg.ldconfigPath)
116+
ldconfigPath := utils.ResolveHostLDConfigPath(cfg.ldconfigPath)
119117
args := []string{filepath.Base(ldconfigPath)}
120118
if containerRootDir != "" {
121119
args = append(args, "-r", containerRootDir)
@@ -146,10 +144,3 @@ func (m command) run(c *cli.Context, cfg *options) error {
146144

147145
return m.Exec(ldconfigPath, args, nil)
148146
}
149-
150-
// resolveLDConfigPath determines the LDConfig path to use for the system.
151-
// On systems such as Ubuntu where `/sbin/ldconfig` is a wrapper around
152-
// /sbin/ldconfig.real, the latter is returned.
153-
func (m command) resolveLDConfigPath(path string) string {
154-
return strings.TrimPrefix(config.NormalizeLDConfigPath("@"+path), "@")
155-
}

cmd/nvidia-cdi-hook/utils/ldconfig.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
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 utils
18+
19+
import (
20+
"strings"
21+
22+
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
23+
)
24+
25+
// ResolveHostLDConfigPath determines the LDConfig path to use for the system.
26+
// On systems such as Ubuntu where `/sbin/ldconfig` is a wrapper around
27+
// /sbin/ldconfig.real, the latter is returned.
28+
func ResolveHostLDConfigPath(path string) string {
29+
return strings.TrimPrefix(config.NormalizeLDConfigPath("@"+path), "@")
30+
}

0 commit comments

Comments
 (0)