mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Deduplicate symlinks
Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
This commit is contained in:
parent
5d7ee25b37
commit
f5d8d248b7
@ -103,14 +103,23 @@ func (p symlink) Locate(pattern string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(candidates) != 1 {
|
||||
return nil, fmt.Errorf("failed to uniquely resolve symlink %v: %v", pattern, candidates)
|
||||
|
||||
var targets []string
|
||||
seen := make(map[string]bool)
|
||||
for _, candidate := range candidates {
|
||||
target, err := filepath.EvalSymlinks(candidate)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to resolve link: %w", err)
|
||||
}
|
||||
if seen[target] {
|
||||
continue
|
||||
}
|
||||
seen[target] = true
|
||||
targets = append(targets, target)
|
||||
}
|
||||
|
||||
target, err := filepath.EvalSymlinks(candidates[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to resolve link: %v", err)
|
||||
if len(targets) != 1 {
|
||||
return nil, fmt.Errorf("failed to locate patern %q: failed to uniquely resolve symlink: %v", pattern, targets)
|
||||
}
|
||||
|
||||
return []string{target}, err
|
||||
return targets, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user