lib/berkshelf/lockfile.rb in berkshelf-4.0.1 vs lib/berkshelf/lockfile.rb in berkshelf-4.1.0
- old
+ new
@@ -394,24 +394,31 @@
unless dependency.version_constraint.satisfies?(graphed.version)
Berkshelf.log.debug " Constraints are not satisfied!"
raise OutdatedDependency.new(graphed, dependency)
end
+ # Locking dependency version to the graphed version if
+ # constraints are satisfied by it.
+ dependency.locked_version = graphed.version
+
if cookbook = dependency.cached_cookbook
Berkshelf.log.debug " Cached cookbook exists"
- Berkshelf.log.debug " Checking dependencies on the cached cookbook"
+ Berkshelf.log.debug " Updating cookbook dependencies if required"
+ graphed.set_dependencies(cookbook.dependencies)
+ end
+ end
- graphed.dependencies.each do |name, constraint|
- Berkshelf.log.debug " Checking #{name} (#{constraint})"
-
- # Unless the cookbook still depends on this key, we want to queue it
- # for unlocking. This is the magic that prevents transitive
- # dependency leaking.
- unless cookbook.dependencies.has_key?(name)
- Berkshelf.log.debug " Not found!"
- unlock(name, true)
- end
+ # Iteratively remove orphan dependencies
+ orphans = true
+ while orphans do
+ orphans = false
+ graph.each do |cookbook|
+ name = cookbook.name
+ unless dependency?(name) or graph.dependency?(name)
+ Berkshelf.log.debug "#{cookbook} identified as orphan; removing it"
+ unlock(name)
+ orphans = true
end
end
end
Berkshelf.log.debug "New lockfile:"
@@ -807,9 +814,13 @@
# the name to use
# @param [#to_s] constraint
# the version constraint to use
def add_dependency(name, constraint)
@dependencies[name.to_s] = constraint.to_s
+ end
+
+ def set_dependencies(dependencies)
+ @dependencies = dependencies.to_hash
end
# @private
def to_s
"#{name} (#{version})"