Class: PatchFinder::MSU

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/patch_finder/msu.rb

Constant Summary collapse

MAX_THREADS =
10

Instance Attribute Summary

Attributes included from Helper

#verbose

Instance Method Summary collapse

Methods included from Helper

#download_file, #download_files, #print_error, #print_line, #print_status, #print_verbose, #print_verbose_error, #read_file, #send_http_get_request

Constructor Details

#initialize(opts = {}) ⇒ MSU

Returns a new instance of MSU.



14
15
16
# File 'lib/patch_finder/msu.rb', line 14

def initialize(opts={})
  self.verbose = opts[:verbose] || false
end

Instance Method Details

Returns the download links.

Parameters:

  • args (Hash)

    Arguments created by the user.

Returns:

  • (Array)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/patch_finder/msu.rb', line 22

def find_msu_download_links(args)
  msb_numbers = collect_msbs(args)

  unless msb_numbers.empty?
    print_verbose("Advisories found (#{msb_numbers.length}): #{msb_numbers * ', '}")
    print_verbose('Please wait while the download links are being collected...')
  end

  download_links = []

  print_verbose("Max number of active collecting clients: #{MAX_THREADS}")
  pool = PatchFinder::ThreadPool.new(MAX_THREADS)

  begin
    msb_numbers.each do |msb|
      pool.schedule do
        links = collect_links_from_msb(msb, args[:regex])
        pool.mutex.synchronize do
          download_links.concat(links)
        end
      end
    end

    pool.shutdown

    sleep(0.5) until pool.eop?
  ensure
    pool.cleanup
  end

  download_links
end