Don't attempt to deflate when compression level is 0

soong_zip -L 0 would attempt to compress with deflate at compression
level 0, then pick store instead of deflate because the overhead of
deflate would always make it larger than the uncompressed size.  Just
use store instead.

Test: m checkbuild
Change-Id: I69610bd755b55d97a47b8c6cf4fbbee3b5632db6
This commit is contained in:
Colin Cross 2018-09-14 15:06:31 -07:00
parent ec06db2709
commit d321629155
1 changed files with 9 additions and 4 deletions

View File

@ -220,14 +220,17 @@ func Run(args ZipArgs) (err error) {
}
pathMappings := []pathMapping{}
noCompression := args.CompressionLevel == 0
for _, fa := range args.FileArgs {
srcs := fa.SourceFiles
if fa.GlobDir != "" {
srcs = append(srcs, recursiveGlobFiles(fa.GlobDir)...)
}
for _, src := range srcs {
if err := fillPathPairs(fa.PathPrefixInZip,
fa.SourcePrefixToStrip, src, &pathMappings, args.NonDeflatedFiles); err != nil {
err := fillPathPairs(fa.PathPrefixInZip, fa.SourcePrefixToStrip, src,
&pathMappings, args.NonDeflatedFiles, noCompression)
if err != nil {
log.Fatal(err)
}
}
@ -267,7 +270,9 @@ func Run(args ZipArgs) (err error) {
return nil
}
func fillPathPairs(prefix, rel, src string, pathMappings *[]pathMapping, nonDeflatedFiles map[string]bool) error {
func fillPathPairs(prefix, rel, src string, pathMappings *[]pathMapping,
nonDeflatedFiles map[string]bool, noCompression bool) error {
src = strings.TrimSpace(src)
if src == "" {
return nil
@ -280,7 +285,7 @@ func fillPathPairs(prefix, rel, src string, pathMappings *[]pathMapping, nonDefl
dest = filepath.Join(prefix, dest)
zipMethod := zip.Deflate
if _, found := nonDeflatedFiles[dest]; found {
if _, found := nonDeflatedFiles[dest]; found || noCompression {
zipMethod = zip.Store
}
*pathMappings = append(*pathMappings,