From 26b71549a593120d09a4c519f9d9342cc86b9352 Mon Sep 17 00:00:00 2001 From: Chris Novakovic Date: Wed, 8 Oct 2025 13:06:35 +0100 Subject: [PATCH 1/2] Writer: append trailing slash to <= 15-byte GNU file names The GNU variant expects all file names to have trailing slashes, regardless of whether they are stored in the string table or in the file name header field. --- writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/writer.go b/writer.go index 65895b3..7fdbc3b 100644 --- a/writer.go +++ b/writer.go @@ -216,7 +216,7 @@ func (aw *Writer) WriteHeader(hdr *Header) error { } aw.string(s.next(16), "/"+strconv.Itoa(offset)) } else { - aw.string(s.next(16), hdr.Name) + aw.string(s.next(16), hdr.Name+"/") } case BSD: // In the BSD variant of the ar format, file names that won't fit in the file name header are From d02a1f6219c995c028878be6d45ec8ebc149d747 Mon Sep 17 00:00:00 2001 From: Chris Novakovic Date: Wed, 8 Oct 2025 16:36:40 +0100 Subject: [PATCH 2/2] Only for real file names --- writer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/writer.go b/writer.go index 7fdbc3b..a7b1d5d 100644 --- a/writer.go +++ b/writer.go @@ -216,7 +216,11 @@ func (aw *Writer) WriteHeader(hdr *Header) error { } aw.string(s.next(16), "/"+strconv.Itoa(offset)) } else { - aw.string(s.next(16), hdr.Name+"/") + // File names beginning with "/" aren't real file names - don't append "/" to them. + if hdr.Name[0] != '/' { + hdr.Name = hdr.Name + "/" + } + aw.string(s.next(16), hdr.Name) } case BSD: // In the BSD variant of the ar format, file names that won't fit in the file name header are