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 <rsesek@chromium.org>
This commit is contained in:
Leonard Grey 2023-05-18 14:09:08 -04:00
parent 5850e262b1
commit 38b6eebda1

View File

@ -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 { type WorkerPool struct {
wg sync.WaitGroup wg sync.WaitGroup
} }
@ -296,7 +319,7 @@ func (dq *DumpQueue) worker() {
dumpSyms := path.Join(*breakpadTools, "dump_syms") dumpSyms := path.Join(*breakpadTools, "dump_syms")
for req := range dq.queue { 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) symfile := fmt.Sprintf("%s_%s.sym", filebase, req.arch)
f, err := os.Create(symfile) f, err := os.Create(symfile)
if err != nil { if err != nil {