lib/stove/packager.rb in stove-3.2.6 vs lib/stove/packager.rb in stove-3.2.7

- old
+ new

@@ -31,16 +31,24 @@ # The cookbook to package. # # @erturn [Stove::Cookbook] attr_reader :cookbook + # Whether to include the new extended metadata attributes. + # + # @return [true, false] + attr_reader :extended_metadata + # Create a new packager instance. # # @param [Stove::Cookbook] # the cookbook to package - def initialize(cookbook) + # @param [true, false] extended_metadata + # include new extended metadata attributes + def initialize(cookbook, extended_metadata = false) @cookbook = cookbook + @extended_metadata = extended_metadata end # A map from physical file path to tarball file path # # @example @@ -68,17 +76,17 @@ end def tarball # Generate the metadata.json on the fly metadata_json = File.join(cookbook.path, 'metadata.json') - File.open(metadata_json, 'wb') do |file| - file.write(cookbook.metadata.to_json) - end + json = JSON.fast_generate(cookbook.metadata.to_hash(extended_metadata)) + File.open(metadata_json, 'wb') { |f| f.write(json) } io = tar(File.dirname(cookbook.path), packaging_slip) tgz = gzip(io) - tempfile = Tempfile.new([cookbook.name, '.tar.gz'], Dir.tmpdir, mode: File::RDWR|File::CREAT|File::EXCL|File::BINARY) + tempfile = Tempfile.new([cookbook.name, '.tar.gz'], Dir.tmpdir) + tempfile.binmode while buffer = tgz.read(1024) tempfile.write(buffer) end