From e1ea0056b9577aee2d7e974792c8c5d62a53a0f9 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 24 Oct 2024 11:55:37 +0200 Subject: [PATCH] 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 --- internal/lookup/symlinks.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/lookup/symlinks.go b/internal/lookup/symlinks.go index aa4c147e..c9bab069 100644 --- a/internal/lookup/symlinks.go +++ b/internal/lookup/symlinks.go @@ -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 }