From fa59d12973ccf675b0e2cfe7f359c06ed7d91ae1 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 22 Oct 2024 11:53:28 +0200 Subject: [PATCH] [no-relnote] Check created outside of create loop Signed-off-by: Evan Lezar --- .../create-symlinks/create-symlinks.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go index 646cb266..50f012ea 100644 --- a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go +++ b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go @@ -95,29 +95,30 @@ func (m command) run(c *cli.Context, cfg *config) error { created := make(map[string]bool) for _, l := range cfg.links.Value() { + if created[l] { + m.logger.Debugf("Link %v already processed", l) + continue + } parts := strings.Split(l, "::") if len(parts) != 2 { m.logger.Warningf("Invalid link specification %v", l) continue } - err := m.createLink(created, cfg.hostRoot, containerRoot, parts[0], parts[1]) + err := m.createLink(cfg.hostRoot, containerRoot, parts[0], parts[1]) if err != nil { m.logger.Warningf("Failed to create link %v: %v", parts, err) } + created[l] = true } return nil } -func (m command) createLink(created map[string]bool, hostRoot string, containerRoot string, target string, link string) error { +func (m command) createLink(hostRoot string, containerRoot string, target string, link string) error { linkPath, err := changeRoot(hostRoot, containerRoot, link) if err != nil { m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err) } - if created[linkPath] { - m.logger.Debugf("Link %v already created", linkPath) - return nil - } targetPath, err := changeRoot(hostRoot, "/", target) if err != nil {