From c30ca0fdc3fba301f3e7c3947b6101b7d07fb9d3 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 17 Oct 2024 15:46:49 +0200 Subject: [PATCH 1/2] Fix typo in error message Signed-off-by: Evan Lezar --- internal/lookup/symlinks/symlink.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/lookup/symlinks/symlink.go b/internal/lookup/symlinks/symlink.go index 991d47cb..1929aaa9 100644 --- a/internal/lookup/symlinks/symlink.go +++ b/internal/lookup/symlinks/symlink.go @@ -25,7 +25,7 @@ import ( func Resolve(filename string) (string, error) { info, err := os.Lstat(filename) if err != nil { - return filename, fmt.Errorf("failed to get file info: %v", info) + return filename, fmt.Errorf("failed to get file info: %w", err) } if info.Mode()&os.ModeSymlink == 0 { return filename, nil From cdf39fbad3ccc40cb750c1dfb4f35c7696fd8269 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 17 Oct 2024 15:47:13 +0200 Subject: [PATCH 2/2] [no-relnote] Use symlinks.Resolve in hook This change removes duplicate logic from the create-symlinks hook and uses symlinks.Resolve instead. Signed-off-by: Evan Lezar --- .../create-symlinks/create-symlinks.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go index b59ce727..781cf800 100644 --- a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go +++ b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go @@ -211,21 +211,14 @@ func changeRoot(current string, new string, path string) (string, error) { // Locate returns the link target of the specified filename or an empty slice if the // specified filename is not a symlink. func (m command) Locate(filename string) ([]string, error) { - info, err := os.Lstat(filename) + target, err := symlinks.Resolve(filename) if err != nil { - return nil, fmt.Errorf("failed to get file info: %v", info) + return nil, err } - if info.Mode()&os.ModeSymlink == 0 { + if target == filename { m.logger.Debugf("%v is not a symlink", filename) return nil, nil } - - target, err := os.Readlink(filename) - if err != nil { - return nil, fmt.Errorf("error checking symlink: %v", err) - } - m.logger.Debugf("Resolved link: '%v' => '%v'", filename, target) - return []string{target}, nil }