feat(go): enrich snapshots with package ownership

This commit is contained in:
Luna 2026-07-22 03:50:55 -07:00
parent 6355fb403d
commit 88d7a6e3b8
No known key found for this signature in database
8 changed files with 149 additions and 54 deletions

View file

@ -47,17 +47,23 @@ type SlowResult struct {
Files map[string]map[string]any
}
func CollectSlow(processes []Process, paths []string) SlowResult {
func CollectSlow(processes []Process, paths []string, owner ...func(string) string) SlowResult {
result := SlowResult{Processes: map[int]map[string]any{}, Files: map[string]map[string]any{}}
packageOwner := func(string) string { return "" }
if len(owner) > 0 && owner[0] != nil {
packageOwner = owner[0]
}
for _, process := range processes {
exe := cleanPath(process.Exe)
if exe == "" {
continue
}
result.Processes[process.PID] = map[string]any{"exe_sha256": boundedHash(exe)}
result.Processes[process.PID] = map[string]any{"exe_sha256": boundedHash(exe), "package_owner": packageOwner(exe)}
}
for _, path := range paths {
result.Files[path] = fileMetadata(path)
metadata := fileMetadata(path)
metadata["package_owner"] = packageOwner(path)
result.Files[path] = metadata
}
return result
}