From b1e956e071e45040937a58483e343194d686357e Mon Sep 17 00:00:00 2001 From: Jeff Solomon Date: Tue, 14 Jan 2020 14:56:36 -0800 Subject: [PATCH] Add a new --rpm-compression-level option which addresses issue 1675: https://github.com/jordansissel/fpm/issues/1675 The value can be a number from 0 to 9 inclusive. The default mirrors the current behavior of 9. If the --rpm-compression value is set to "none", this value is ignored. Setting the value to 5 sped up RPM creation on my RPM from 9 to 3 minutes. --- lib/fpm/package/rpm.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index 3430a64b92..12761f1808 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -24,10 +24,10 @@ class FPM::Package::RPM < FPM::Package COMPRESSION_MAP = { "none" => "w0.gzdio", - "xz" => "w9.xzdio", - "xzmt" => "w9T.xzdio", - "gzip" => "w9.gzdio", - "bzip2" => "w9.bzdio" + "xz" => ".xzdio", + "xzmt" => "T.xzdio", + "gzip" => ".gzdio", + "bzip2" => ".bzdio" } unless defined?(COMPRESSION_MAP) option "--use-file-permissions", :flag, @@ -68,6 +68,15 @@ class FPM::Package::RPM < FPM::Package value.downcase end + option "--compression-level", "[0-9]", "Select a compression level. 0 is store-only. 9 is max compression.", + :default => "9" do |value| + valint = value.to_i + unless value =~ /^\d$/ && valint >= 0 && valint <= 9 + raise "Invalid compression level '#{value}'. Valid values are integers between 0 and 9 inclusive." + end + valint + end + option "--compression", COMPRESSION_MAP.keys.join("|"), "Select a compression method. gzip works on the most platforms.", :default => "gzip" do |value| @@ -602,7 +611,12 @@ def to_s(format=nil) end # def to_s def payload_compression - return COMPRESSION_MAP[attributes[:rpm_compression]] + if attributes[:rpm_compression] == 'none' + # when 'none' ignore any compression level and return w0.gzdio + return COMPRESSION_MAP[attributes[:rpm_compression]] + else + return "w#{attributes[:rpm_compression_level]}" + COMPRESSION_MAP[attributes[:rpm_compression]] + end end # def payload_compression def digest_algorithm