Fix bug in sorting of symlink chain

Since we use a map to keep track of the elements of a symlink chain
the construction of the final list of located elements is not stable.
This change constructs the output as this is being discovered and as
such maintains the original ordering.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2024-10-24 11:55:37 +02:00
parent c802c3089c
commit e1ea0056b9

View File

@ -62,6 +62,7 @@ func (p symlinkChain) Locate(pattern string) ([]string, error) {
return candidates, nil
}
var filenames []string
found := make(map[string]bool)
for len(candidates) > 0 {
candidate := candidates[0]
@ -70,6 +71,7 @@ func (p symlinkChain) Locate(pattern string) ([]string, error) {
continue
}
found[candidate] = true
filenames = append(filenames, candidate)
target, err := symlinks.Resolve(candidate)
if err != nil {
@ -88,11 +90,6 @@ func (p symlinkChain) Locate(pattern string) ([]string, error) {
candidates = append(candidates, target)
}
}
var filenames []string
for f := range found {
filenames = append(filenames, f)
}
return filenames, nil
}