Skip to content

Commit cdf39fb

Browse files
committed
[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 <[email protected]>
1 parent c30ca0f commit cdf39fb

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,14 @@ func changeRoot(current string, new string, path string) (string, error) {
211211
// Locate returns the link target of the specified filename or an empty slice if the
212212
// specified filename is not a symlink.
213213
func (m command) Locate(filename string) ([]string, error) {
214-
info, err := os.Lstat(filename)
214+
target, err := symlinks.Resolve(filename)
215215
if err != nil {
216-
return nil, fmt.Errorf("failed to get file info: %v", info)
216+
return nil, err
217217
}
218-
if info.Mode()&os.ModeSymlink == 0 {
218+
if target == filename {
219219
m.logger.Debugf("%v is not a symlink", filename)
220220
return nil, nil
221221
}
222-
223-
target, err := os.Readlink(filename)
224-
if err != nil {
225-
return nil, fmt.Errorf("error checking symlink: %v", err)
226-
}
227-
228222
m.logger.Debugf("Resolved link: '%v' => '%v'", filename, target)
229-
230223
return []string{target}, nil
231224
}

0 commit comments

Comments
 (0)