Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
initial spike generating some checksums for Gemfile.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
hone committed Mar 10, 2013
1 parent 4f2ea14 commit 7dd7e49
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/bundler/definition.rb
Expand Up @@ -281,6 +281,16 @@ def to_lock

def checksum(file)
contents = ""
handled = []
dependencies.map {|d|
d.all_deps(d) }.flatten.
sort_by { |d| d.to_s }.
each do |dep|
next if handled.include?(dep.name)
contents << dep.to_checksum
contents << "\n"
handled << dep.name
end

File.open(file, 'wb'){|f| f.puts(contents) }
rescue Errno::EACCES
Expand All @@ -290,6 +300,9 @@ def checksum(file)
"#{File.expand_path(file)}"
end

def to_checksum
end

def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
changes = false

Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/dependency.rb
Expand Up @@ -79,6 +79,10 @@ def to_lock
out << "\n"
end

def to_checksum
out = super
end

private

def on_18?
Expand Down
6 changes: 6 additions & 0 deletions lib/bundler/rubygems_ext.rb
Expand Up @@ -92,6 +92,7 @@ def dependencies_to_gemfile(dependencies, group = nil)
end

class Dependency
require 'digest/sha2'
attr_accessor :source, :groups

alias eql? ==
Expand All @@ -115,6 +116,11 @@ def to_lock
out
end

def to_checksum
spec = to_spec
"#{spec.full_name}:#{Digest::SHA256.hexdigest(File.read(spec.cache_file))}"
end

def all_deps(dep = self)
deps = dep.to_spec.dependencies.select {|d| d.type == :runtime }

Expand Down
22 changes: 20 additions & 2 deletions spec/install/gems/simple_case_spec.rb
Expand Up @@ -340,14 +340,32 @@
end

context "Gemfile.lock.asc" do
require 'digest/sha2'

it "creates a Gemfile.lock.asc" do
install_gemfile(<<-G)
gemfile(<<-G)
source "file://#{gem_repo1}"
gem 'foo'
gem 'thin'
G

bundle "install --path vendor/bundle"

ruby_version = Bundler::SystemRubyVersion.new
ruby_abi = RbConfig::CONFIG['ruby_version']
cache_dir = "vendor/bundle/#{ruby_version.engine}/#{ruby_abi}/cache"
hashes = {}
['thin-1.0', 'rack-1.0.0'].each do |gem|
hashes[gem] = Digest::SHA256.hexdigest(File.read(bundled_app("#{cache_dir}/#{gem}.gem")))
end

expect(bundled_app("Gemfile.lock.asc")).to exist

contents = File.read(bundled_app("Gemfile.lock.asc")).split("\n")
contents.each do |line|
gem, checksum = line.split(":")
expect(hashes[gem]).to eq(checksum)
end
end

context "on empty Gemfile" do
Expand Down

0 comments on commit 7dd7e49

Please sign in to comment.