summaryrefslogtreecommitdiff
path: root/lib/chef/node_map.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-01-22 11:41:11 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2018-01-22 11:41:11 -0800
commite32c1733567455dc6f3ce0f702d981f261413b90 (patch)
treee445572574b7c4897a869c84a1c2e77c0bb89e4a /lib/chef/node_map.rb
parent9439fd6e5da8d87f48ebc1b6de4b7c09c8654c39 (diff)
downloadchef-e32c1733567455dc6f3ce0f702d981f261413b90.tar.gz
Convert node map to last-writer-wins for ties
We still bind preferentially by specificity, but for ties with specificity we now prefer last-writer-wins instead of the alphabetic by class name method we had before (that was never documented and I'm pretty certain nobody understood). So now `provides(:whatever) { true }` in a cookbook should always win over core. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/node_map.rb')
-rw-r--r--lib/chef/node_map.rb28
1 files changed, 5 insertions, 23 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index dde93a437d..ecd5c9df8f 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -1,6 +1,6 @@
#
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2014-2017, Chef Software Inc.
+# Copyright:: Copyright 2014-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -192,8 +192,10 @@ class Chef
!!canonical == !!matcher[:canonical]
end
- # @api private
- def dispatch_compare_matchers(key, new_matcher, matcher)
+ #
+ # "provides" lines with identical filters sort by class name (ascending).
+ #
+ def compare_matchers(key, new_matcher, matcher)
cmp = compare_matcher_properties(new_matcher[:block], matcher[:block])
return cmp if cmp != 0
cmp = compare_matcher_properties(new_matcher[:platform_version], matcher[:platform_version])
@@ -210,26 +212,6 @@ class Chef
0
end
- #
- # "provides" lines with identical filters sort by class name (ascending).
- #
- def compare_matchers(key, new_matcher, matcher)
- cmp = dispatch_compare_matchers(key, new_matcher, matcher)
- if cmp == 0
- # Sort by class name (ascending) as well, if all other properties
- # are exactly equal
- # XXX: remove this in Chef-14 and use last-writer-wins (prepend if they match)
- if !new_matcher[:override]
- # we only sort classes, which only sorts the handler array, this magically does not sort
- # the priority array via the invisible else here.
- if new_matcher[:klass].is_a?(Class)
- cmp = compare_matcher_properties(new_matcher[:klass].name, matcher[:klass].name)
- end
- end
- end
- cmp
- end
-
def compare_matcher_properties(a, b)
# falsity comparisons here handle both "nil" and "false"
return 1 if !a && b