mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 13:35:00 +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)
|
||||
}
|
||||
|
||||
target, err := filepath.EvalSymlinks(candidates[0])
|
||||
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: %v", err)
|
||||
return nil, fmt.Errorf("failed to resolve link: %w", err)
|
||||
}
|
||||
if seen[target] {
|
||||
continue
|
||||
}
|
||||
seen[target] = true
|
||||
targets = append(targets, target)
|
||||
}
|
||||
|
||||
return []string{target}, err
|
||||
if len(targets) != 1 {
|
||||
return nil, fmt.Errorf("failed to locate patern %q: failed to uniquely resolve symlink: %v", pattern, targets)
|
||||
}
|
||||
return targets, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user