From bfea673d6a11856e394c3181219bc4a722eaacef Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 22 Oct 2024 12:11:41 +0200 Subject: [PATCH] [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 --- .../create-symlinks/create-symlinks.go | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go index e9a6033f..0d8d0867 100644 --- a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go +++ b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go @@ -33,7 +33,6 @@ type command struct { } type config struct { - hostRoot string links cli.StringSlice containerSpec string } @@ -65,12 +64,6 @@ func (m command) build() *cli.Command { Destination: &cfg.links, }, // The following flags are testing-only flags. - &cli.StringFlag{ - Name: "host-root", - Usage: "The root on the host filesystem to use to resolve symlinks. This is only intended for testing.", - Destination: &cfg.hostRoot, - Hidden: true, - }, &cli.StringFlag{ Name: "container-spec", 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 { continue } - err := m.createLink(cfg.hostRoot, containerRoot, parts[0], parts[1]) + err := m.createLink(containerRoot, parts[0], parts[1]) if err != nil { m.logger.Warningf("Failed to create link %v: %v", parts, err) } @@ -114,8 +107,8 @@ func (m command) run(c *cli.Context, cfg *config) error { return nil } -func (m command) createLink(hostRoot string, containerRoot string, targetPath string, link string) error { - linkPath, err := changeRoot(hostRoot, containerRoot, link) +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) } @@ -133,19 +126,10 @@ func (m command) createLink(hostRoot string, containerRoot string, targetPath st return nil } -func changeRoot(current string, new string, path string) (string, error) { +func changeRoot(new string, path string) (string, error) { if !filepath.IsAbs(path) { return path, nil } - relative := path - if current != "" { - r, err := filepath.Rel(current, path) - if err != nil { - return "", err - } - relative = r - } - - return filepath.Join(new, relative), nil + return filepath.Join(new, path), nil }