Have soong_zip not write a data descriptor for non-compressed files
Bug: 64536066
Test: m -j blueprint_tools && cd /tmp && mkdir zip && \
cd zip && touch empty-file && \
echo empty-file > files.list && \
soong_zip -o zip.zip -C . -l files.list && \
jar -xvf zip.zip && echo ok
Change-Id: Iac5797aab5282237fa1cc902e6b068a7937c012a
diff --git a/third_party/zip/android.go b/third_party/zip/android.go
index f3b6055..bde3afa 100644
--- a/third_party/zip/android.go
+++ b/third_party/zip/android.go
@@ -19,6 +19,8 @@
"io"
)
+const DataDescriptorFlag = 0x8
+
func (w *Writer) CopyFrom(orig *File, newName string) error {
if w.last != nil && !w.last.closed {
if err := w.last.close(); err != nil {
@@ -30,7 +32,7 @@
fileHeader := orig.FileHeader
fileHeader.Name = newName
fh := &fileHeader
- fh.Flags |= 0x8
+ fh.Flags |= DataDescriptorFlag
// The zip64 extras change between the Central Directory and Local File Header, while we use
// the same structure for both. The Local File Haeder is taken care of by us writing a data
@@ -122,7 +124,7 @@
return nil, errors.New("archive/zip: invalid duplicate FileHeader")
}
- fh.Flags |= 0x8 // we will write a data descriptor
+ fh.Flags |= DataDescriptorFlag // we will write a data descriptor
fh.CreatorVersion = fh.CreatorVersion&0xff00 | zipVersion20 // preserve compatibility byte
fh.ReaderVersion = zipVersion20
@@ -149,6 +151,17 @@
return fw, nil
}
+// Updated version of CreateHeader that doesn't enforce writing a data descriptor
+func (w *Writer) CreateHeaderAndroid(fh *FileHeader) (io.Writer, error) {
+ writeDataDescriptor := fh.Method != Store
+ if writeDataDescriptor {
+ fh.Flags &= DataDescriptorFlag
+ } else {
+ fh.Flags &= ^uint16(DataDescriptorFlag)
+ }
+ return w.createHeaderImpl(fh)
+}
+
type compressedFileWriter struct {
fileWriter
}