diff options
author | 2017-08-24 14:11:27 -0700 | |
---|---|---|
committer | 2017-08-24 14:43:35 -0700 | |
commit | c5eb66d16b82279d33746d312e91793970e0310f (patch) | |
tree | 087757782b42ab20087265365536545b8a1a0d4b /third_party/zip/android.go | |
parent | 6dd56e0f4a2614590064290016984a7d1cb574c6 (diff) |
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
Diffstat (limited to 'third_party/zip/android.go')
-rw-r--r-- | third_party/zip/android.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/third_party/zip/android.go b/third_party/zip/android.go index f3b605557..bde3afa4f 100644 --- a/third_party/zip/android.go +++ b/third_party/zip/android.go @@ -19,6 +19,8 @@ import ( "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 @@ func (w *Writer) CopyFrom(orig *File, newName string) error { 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 @@ func (w *Writer) CreateCompressedHeader(fh *FileHeader) (io.WriteCloser, error) 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 @@ func (w *Writer) CreateCompressedHeader(fh *FileHeader) (io.WriteCloser, error) 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 } |