From d3216291554ba3613042535f1e6918d3b50fa1bf Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 14 Sep 2018 15:06:31 -0700 Subject: [PATCH] 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 --- zip/zip.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/zip/zip.go b/zip/zip.go index a89fa9f2b..a8df51e2c 100644 --- a/zip/zip.go +++ b/zip/zip.go @@ -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,