Sha256: 333a35700206f5fb7d8f852d9142585d02272dfe5187d857a3e9c172b5388d66

Contents?: true

Size: 1.56 KB

Versions: 70

Compression:

Stored size: 1.56 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/opt-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/opt" if folder_exist?("opt")
        paths << "stage/rack" if folder_exist?("rack")
        # Important to have stage/code at the end, since its md5 checksum depends
        # on the previous folders.
        paths << "stage/code"
        paths
      end

      def folder_exist?(folder)
        path = "#{Jets.build_root}/stage/#{folder}"
        File.directory?(path)
      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

70 entries across 70 versions & 2 rubygems

Version Path
jets-1.9.7 lib/jets/builders/md5.rb
jets-1.9.6 lib/jets/builders/md5.rb
jets-1.9.5 lib/jets/builders/md5.rb
jets-1.9.4 lib/jets/builders/md5.rb
jets-1.9.3 lib/jets/builders/md5.rb
jets-1.9.2 lib/jets/builders/md5.rb
jets-1.9.1 lib/jets/builders/md5.rb
jets-1.9.0 lib/jets/builders/md5.rb
jets-1.8.14 lib/jets/builders/md5.rb
jets-1.8.13 lib/jets/builders/md5.rb
jets-1.8.12 lib/jets/builders/md5.rb
jets-1.8.11 lib/jets/builders/md5.rb
jets-1.8.10 lib/jets/builders/md5.rb
jets-1.8.9 lib/jets/builders/md5.rb
jets-1.8.8 lib/jets/builders/md5.rb
jets-1.8.7 lib/jets/builders/md5.rb
jets-1.8.6 lib/jets/builders/md5.rb
jets-1.8.5 lib/jets/builders/md5.rb
jets-1.8.4 lib/jets/builders/md5.rb
jets-1.8.3 lib/jets/builders/md5.rb