Skip to content

Commit d0d85a8

Browse files
elezarcdesiniotis
authored andcommitted
Always use paths relative to the container root for links
This chagne ensures that we always treat the link path as a path relative to the container root. Without this change, relative paths in link paths would result links being created relative to the current working directory where the hook is executed. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent bfea673 commit d0d85a8

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ func (m command) run(c *cli.Context, cfg *config) error {
108108
}
109109

110110
func (m command) createLink(containerRoot string, targetPath string, link string) error {
111-
linkPath, err := changeRoot(containerRoot, link)
112-
if err != nil {
113-
m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err)
114-
}
111+
linkPath := filepath.Join(containerRoot, link)
115112

116113
m.logger.Infof("Symlinking %v to %v", linkPath, targetPath)
117-
err = os.MkdirAll(filepath.Dir(linkPath), 0755)
114+
err := os.MkdirAll(filepath.Dir(linkPath), 0755)
118115
if err != nil {
119116
return fmt.Errorf("failed to create directory: %v", err)
120117
}
@@ -125,11 +122,3 @@ func (m command) createLink(containerRoot string, targetPath string, link string
125122

126123
return nil
127124
}
128-
129-
func changeRoot(new string, path string) (string, error) {
130-
if !filepath.IsAbs(path) {
131-
return path, nil
132-
}
133-
134-
return filepath.Join(new, path), nil
135-
}

0 commit comments

Comments
 (0)