From fa5b4e909b566bf00861c46ecead178de2c73235 Mon Sep 17 00:00:00 2001 From: Chris Gross Date: Wed, 2 Jun 2021 12:56:08 -0700 Subject: [PATCH] Use broader permissions when archiving files. Using broader premissions for archived files allows them to be more easily used when extracted. For example, defaulting regular files to 0644 will allow other tooling to use a file without the need to change permissions manually. Bug: 189919409 Test: m dist and inspected file permissions of archived files Change-Id: I4a0f8075206391254c639ecf865639bb9e8df0bf --- jar/jar.go | 4 ++-- zip/zip.go | 6 +++--- zip/zip_test.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jar/jar.go b/jar/jar.go index a8f06a4f3..f164ee1ee 100644 --- a/jar/jar.go +++ b/jar/jar.go @@ -77,7 +77,7 @@ func MetaDirFileHeader() *zip.FileHeader { Name: MetaDir, Extra: []byte{MetaDirExtra[1], MetaDirExtra[0], 0, 0}, } - dirHeader.SetMode(0700 | os.ModeDir) + dirHeader.SetMode(0755 | os.ModeDir) dirHeader.SetModTime(DefaultTime) return dirHeader @@ -95,7 +95,7 @@ func ManifestFileContents(contents []byte) (*zip.FileHeader, []byte, error) { Method: zip.Store, UncompressedSize64: uint64(len(b)), } - fh.SetMode(0700) + fh.SetMode(0644) fh.SetModTime(DefaultTime) return fh, b, nil diff --git a/zip/zip.go b/zip/zip.go index 6e412c956..ae379f52e 100644 --- a/zip/zip.go +++ b/zip/zip.go @@ -656,9 +656,9 @@ func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar, srcJar UncompressedSize64: uint64(fileSize), } - mode := os.FileMode(0600) + mode := os.FileMode(0644) if executable { - mode = 0700 + mode = 0755 } header.SetMode(mode) @@ -955,7 +955,7 @@ func (z *ZipWriter) writeDirectory(dir string, src string, emulateJar bool) erro dirHeader = &zip.FileHeader{ Name: cleanDir + "/", } - dirHeader.SetMode(0700 | os.ModeDir) + dirHeader.SetMode(0755 | os.ModeDir) } dirHeader.SetModTime(z.time) diff --git a/zip/zip_test.go b/zip/zip_test.go index 441dea3bd..79cc0b4b7 100644 --- a/zip/zip_test.go +++ b/zip/zip_test.go @@ -62,7 +62,7 @@ func fh(name string, contents []byte, method uint16) zip.FileHeader { Method: method, CRC32: crc32.ChecksumIEEE(contents), UncompressedSize64: uint64(len(contents)), - ExternalAttrs: (syscall.S_IFREG | 0600) << 16, + ExternalAttrs: (syscall.S_IFREG | 0644) << 16, } } @@ -72,7 +72,7 @@ func fhManifest(contents []byte) zip.FileHeader { Method: zip.Store, CRC32: crc32.ChecksumIEEE(contents), UncompressedSize64: uint64(len(contents)), - ExternalAttrs: (syscall.S_IFREG | 0700) << 16, + ExternalAttrs: (syscall.S_IFREG | 0644) << 16, } } @@ -92,7 +92,7 @@ func fhDir(name string) zip.FileHeader { Method: zip.Store, CRC32: crc32.ChecksumIEEE(nil), UncompressedSize64: 0, - ExternalAttrs: (syscall.S_IFDIR|0700)<<16 | 0x10, + ExternalAttrs: (syscall.S_IFDIR|0755)<<16 | 0x10, } }