diff --git a/activation/files_unix.go b/activation/files_unix.go index bf7671dd..d51dcbbf 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 := 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 +} diff --git a/activation/files_windows.go b/activation/files_windows.go index d391bf00..3f2aa8af 100644 --- a/activation/files_windows.go +++ b/activation/files_windows.go @@ -19,3 +19,22 @@ import "os" func Files(unsetEnv bool) []*os.File { return nil } + +// FilesWithNames maps fd names to a set of os.File pointers. +func FilesWithNames() map[string][]*os.File { + files := 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 +}