facter-1.5.2-sortfix2.patch

Sort facts using stable sort algorithm - Robin Hill, 10/16/2008 09:16 am

Download (1010 Bytes)

facter-1.5.2-patched/lib/facter/util/fact.rb 2008-10-16 10:04:09.000000000 +0100
1 1
require 'facter'
2 2
require 'facter/util/resolution'
3 3

  
4
class Array
5
    def stable_sort
6
        n = 0
7
        c = lambda { |x| n+= 1; [x, n]}
8
        if block_given?
9
            sort { |a, b|
10
                yield(c.call(a), c.call(b))
11
            }
12
        else
13
            sort_by &c
14
        end
15
    end
16
end
17

  
4 18
class Facter::Util::Fact
5 19
    TIMEOUT = 5
6 20

  
......
43 57
        # a sorted list for looking up values.
44 58
        #  We always want to look them up in the order of number of
45 59
        # confines, so the most restricted resolution always wins.
46
        @resolves.sort! { |a, b| b.length <=> a.length }
60
        @resolves = @resolves.stable_sort { |a, b| b.length <=> a.length }
47 61

  
48 62
        return resolve
49 63
    end