Sha256: c8a821d50fcf57a3561cad881d1f82e05bed926d45fd162a8749067d1bd2c021

Contents?: true

Size: 1.45 KB

Versions: 26

Compression:

Stored size: 1.45 KB

Contents

require 'digest'

# Resolves the chicken-and-egg problem with md5 checksums. The handlers need
# to reference files with the md5 checksum.  The files are the:
#
#   jets/code/rack-checksum.zip
#   jets/code/bundled-checksum.zip
#
# We compute the checksums before we generate the node shim handlers.
class Jets::Builders
  class Md5
    class << self
      @@checksums = {}
      def checksums
        @@checksums
      end

      def stage_folders
        paths = []
        paths << "stage/bundled" if Jets.lazy_load?
        paths << "stage/rack" if Jets.rack?
        # Important to have stage/code at the end, since it will use the other
        # 'symlinked' folders to adjust the md5 hash.
        paths << "stage/code"
        paths
      end

      def compute!
        stage_folders.each do |path|
          @@checksums[path] = dir(path)
        end
        @@checksums
      end

      def dir(short_path)
        path = "#{Jets.build_root}/#{short_path}"
        files = Dir["#{path}/**/*"]
        files.reject! { |f| File.directory?(f) }
             .reject! { |f| File.symlink?(f) }
        content = files.map do |f|
          Digest::MD5.file(f).to_s[0..7]
        end.join

        # The stage/code md5 sha depends on the other 'symlinked' folders.
        if short_path == "stage/code"
          content += @@checksums.values.join
        end

        md5 = Digest::MD5.new
        md5.update(content)
        md5.hexdigest.to_s[0..7]
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
jets-1.2.1 lib/jets/builders/md5.rb
jets-1.2.0 lib/jets/builders/md5.rb
jets-1.1.5 lib/jets/builders/md5.rb
jets-1.1.4 lib/jets/builders/md5.rb
jets-1.1.3 lib/jets/builders/md5.rb
jets-1.1.2 lib/jets/builders/md5.rb
jets-1.1.1 lib/jets/builders/md5.rb
jets-1.1.0 lib/jets/builders/md5.rb
jets-1.0.18 lib/jets/builders/md5.rb
jets-1.0.17 lib/jets/builders/md5.rb
jets-1.0.16 lib/jets/builders/md5.rb
jets-1.0.15 lib/jets/builders/md5.rb
jets-1.0.13 lib/jets/builders/md5.rb
jets-1.0.12 lib/jets/builders/md5.rb
jets-1.0.11 lib/jets/builders/md5.rb
jets-1.0.10 lib/jets/builders/md5.rb
jets-1.0.9 lib/jets/builders/md5.rb
jets-1.0.8 lib/jets/builders/md5.rb
jets-1.0.7 lib/jets/builders/md5.rb
jets-1.0.6 lib/jets/builders/md5.rb