From 38b6eebda19a4127299a7bf806c67868dde7fca3 Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Thu, 18 May 2023 14:09:08 -0400 Subject: [PATCH] Mac: shorten sym file names in upload_system_symbols macOS caps filenames at 255 characters. When upload_system_symbols runs `dump_syms`, the resulting filename is based on a mangled version of the file's full path. In some circumstances (for example, the dumped file itself lives in a temp directory), this name can exceed the max. This change replaces the current mangling by mapping each path component but the last to its first initial, greatly shortening the resulting filename. Bug: 1400770 Change-Id: I68203a98eda2912893c5d8f7c676faee17e39e91 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4519231 Reviewed-by: Robert Sesek --- .../upload_system_symbols.go | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/tools/mac/upload_system_symbols/upload_system_symbols.go b/src/tools/mac/upload_system_symbols/upload_system_symbols.go index ba067276..f34c288a 100644 --- a/src/tools/mac/upload_system_symbols/upload_system_symbols.go +++ b/src/tools/mac/upload_system_symbols/upload_system_symbols.go @@ -163,6 +163,29 @@ func main() { } } +// manglePath reduces an absolute filesystem path to a string suitable as the +// base for a file name which encodes some of the original path. The result +// concatenates the leading initial from each path component except the last to +// the last path component; for example /System/Library/Frameworks/AppKit +// becomes SLFAppKit. +// Assumes ASCII. +func manglePath(path string) string { + components := strings.Split(path, "/") + n := len(components) + builder := strings.Builder{} + for i, component := range components { + if len(component) == 0 { + continue + } + if i < n-1 { + builder.WriteString(component[:1]) + } else { + builder.WriteString(component) + } + } + return builder.String() +} + type WorkerPool struct { wg sync.WaitGroup } @@ -296,7 +319,7 @@ func (dq *DumpQueue) worker() { dumpSyms := path.Join(*breakpadTools, "dump_syms") for req := range dq.queue { - filebase := path.Join(dq.dumpPath, strings.Replace(req.path, "/", "_", -1)) + filebase := path.Join(dq.dumpPath, manglePath(req.path)) symfile := fmt.Sprintf("%s_%s.sym", filebase, req.arch) f, err := os.Create(symfile) if err != nil {