From 3b1abc890c2ab4df1321a88487119e132e262faf Mon Sep 17 00:00:00 2001 From: Aaron Paterson <9441877+MayCXC@users.noreply.github.com> Date: Wed, 9 Oct 2024 01:43:45 -0400 Subject: [PATCH] add FilesWithNames() --- activation/files_unix.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/activation/files_unix.go b/activation/files_unix.go index bf7671dd..29c27000 100644 --- a/activation/files_unix.go +++ b/activation/files_unix.go @@ -68,3 +68,22 @@ func Files(unsetEnv bool) []*os.File { return files } + +// FilesWithNames maps fd names to a set of os.File pointers. +func FilesWithNames() map[string][]*os.File { + files := activation.Files(true) + filesWithNames := map[string][]*os.File{} + + for _, f := range files { + current, ok := filesWithNames[f.Name()] + + if !ok { + current = []*os.File{} + filesWithNames[f.Name()] = current + } + + filesWithNames[f.Name()] = append(current, f) + } + + return filesWithNames +}