Skip to content

Commit bfea673

Browse files
elezarcdesiniotis
authored andcommitted
[no-relnote] Remove unused hostRoot argument
The hostRoot argument is always empty and not applicable to how links are specified. Links are specified by the paths in the container filesystem and as such the only transform required to change the root is a join of the filepath. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 6a6a3e6 commit bfea673

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type command struct {
3333
}
3434

3535
type config struct {
36-
hostRoot string
3736
links cli.StringSlice
3837
containerSpec string
3938
}
@@ -65,12 +64,6 @@ func (m command) build() *cli.Command {
6564
Destination: &cfg.links,
6665
},
6766
// The following flags are testing-only flags.
68-
&cli.StringFlag{
69-
Name: "host-root",
70-
Usage: "The root on the host filesystem to use to resolve symlinks. This is only intended for testing.",
71-
Destination: &cfg.hostRoot,
72-
Hidden: true,
73-
},
7467
&cli.StringFlag{
7568
Name: "container-spec",
7669
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.",
@@ -105,7 +98,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
10598
continue
10699
}
107100

108-
err := m.createLink(cfg.hostRoot, containerRoot, parts[0], parts[1])
101+
err := m.createLink(containerRoot, parts[0], parts[1])
109102
if err != nil {
110103
m.logger.Warningf("Failed to create link %v: %v", parts, err)
111104
}
@@ -114,8 +107,8 @@ func (m command) run(c *cli.Context, cfg *config) error {
114107
return nil
115108
}
116109

117-
func (m command) createLink(hostRoot string, containerRoot string, targetPath string, link string) error {
118-
linkPath, err := changeRoot(hostRoot, containerRoot, link)
110+
func (m command) createLink(containerRoot string, targetPath string, link string) error {
111+
linkPath, err := changeRoot(containerRoot, link)
119112
if err != nil {
120113
m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err)
121114
}
@@ -133,19 +126,10 @@ func (m command) createLink(hostRoot string, containerRoot string, targetPath st
133126
return nil
134127
}
135128

136-
func changeRoot(current string, new string, path string) (string, error) {
129+
func changeRoot(new string, path string) (string, error) {
137130
if !filepath.IsAbs(path) {
138131
return path, nil
139132
}
140133

141-
relative := path
142-
if current != "" {
143-
r, err := filepath.Rel(current, path)
144-
if err != nil {
145-
return "", err
146-
}
147-
relative = r
148-
}
149-
150-
return filepath.Join(new, relative), nil
134+
return filepath.Join(new, path), nil
151135
}

0 commit comments

Comments
 (0)