Add symlinks package with Resolve function

This change adds a symlinks.Resolve function for resolving symlinks and
updates usages across the code to make use of it.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2023-05-11 14:04:16 +02:00
parent e7d2a9c212
commit 927ec78b6e
4 changed files with 45 additions and 27 deletions

View File

@@ -29,6 +29,7 @@ import (
"syscall"
"unsafe"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
log "github.com/sirupsen/logrus"
)
@@ -288,16 +289,7 @@ func (c *ldcache) resolve(target string) (string, error) {
c.logger.Debugf("checking %v", string(name))
info, err := os.Lstat(name)
if err != nil {
return "", fmt.Errorf("failed to get file info: %v", info)
}
if info.Mode()&os.ModeSymlink == 0 {
c.logger.Debugf("Resolved regular file: %v", name)
return name, nil
}
link, err := os.Readlink(name)
link, err := symlinks.Resolve(name)
if err != nil {
return "", fmt.Errorf("failed to resolve symlink: %v", err)
}