From 273d97af8502059193ccb6a188422f9d22eaf106 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 16 Mar 2025 01:20:09 +0900 Subject: ldd: lib paths resolve function This is what always happens right after a ldd call, so implement it here. Signed-off-by: Ophestra --- ldd/path.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ldd/path.go (limited to 'ldd') diff --git a/ldd/path.go b/ldd/path.go new file mode 100644 index 00000000..4e41ce74 --- /dev/null +++ b/ldd/path.go @@ -0,0 +1,21 @@ +package ldd + +import ( + "path" + "slices" +) + +// Path returns a deterministic, deduplicated slice of absolute directory paths in entries. +func Path(entries []*Entry) []string { + p := make([]string, 0, len(entries)*2) + for _, entry := range entries { + if path.IsAbs(entry.Path) { + p = append(p, path.Dir(entry.Path)) + } + if path.IsAbs(entry.Name) { + p = append(p, path.Dir(entry.Name)) + } + } + slices.Sort(p) + return slices.Compact(p) +} -- cgit v1.3.1