From d0d85a8c5c1fd6fdd4ea63b8bb0315cba82c2a6d Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 22 Oct 2024 12:16:31 +0200 Subject: [PATCH] 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 --- .../create-symlinks/create-symlinks.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go index 0d8d0867..1526b049 100644 --- a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go +++ b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go @@ -108,13 +108,10 @@ func (m command) run(c *cli.Context, cfg *config) error { } func (m command) createLink(containerRoot string, targetPath string, link string) error { - linkPath, err := changeRoot(containerRoot, link) - if err != nil { - m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err) - } + linkPath := filepath.Join(containerRoot, link) m.logger.Infof("Symlinking %v to %v", linkPath, targetPath) - err = os.MkdirAll(filepath.Dir(linkPath), 0755) + err := os.MkdirAll(filepath.Dir(linkPath), 0755) if err != nil { return fmt.Errorf("failed to create directory: %v", err) } @@ -125,11 +122,3 @@ func (m command) createLink(containerRoot string, targetPath string, link string return nil } - -func changeRoot(new string, path string) (string, error) { - if !filepath.IsAbs(path) { - return path, nil - } - - return filepath.Join(new, path), nil -}