| 782 | |
| 783 | class Downloader |
| 784 | def download |
| 785 | progress_label = "Downloading: #{target_base_path}" |
| 786 | progress_reporter = ProgressReporter.new(progress_label) |
| 787 | prefix = [target_base_path, @prefix].compact.join("/") |
| 788 | open_client_pool(prefix) do |client_pool| |
| 789 | thread_pool = ThreadPool.new(thread_pool_use_case) do |path, output_path| |
| 790 | client_pool.pull do |client| |
| 791 | client.download(path, output_path) |
| 792 | end |
| 793 | progress_reporter.advance |
| 794 | end |
| 795 | files = client_pool.pull do |client| |
| 796 | client.files |
| 797 | end |
| 798 | if @target == :base and yum_repository? |
| 799 | # Download Yum repository metadata efficiently. We have many |
| 800 | # old unused repodata/*-.{sqlite,xml} files because we don't |
| 801 | # remove old unused repodata/*-.{sqlite,xml}. We want to |
| 802 | # download only used Yum repository metadata. We can find it |
| 803 | # by checking <location href="..."/> in repomd.xml. |
| 804 | dynamic_paths = [] |
| 805 | files.each do |path| |
| 806 | next unless File.basename(path) == "repomd.xml" |
| 807 | output_path = "#{@destination}/#{path}" |
| 808 | yield(output_path) |
| 809 | output_dir = File.dirname(output_path) |
| 810 | FileUtils.mkdir_p(output_dir) |
| 811 | progress_reporter.increment_max |
| 812 | client_pool.pull do |client| |
| 813 | client.download(path, output_path) |
| 814 | end |
| 815 | progress_reporter.advance |
| 816 | base_dir = File.dirname(File.dirname(path)) |
| 817 | File.read(output_path).scan(/<location\s+href="(.+?)"/) do |href,| |
| 818 | dynamic_paths << "#{base_dir}/#{href}" |
| 819 | end |
| 820 | end |
| 821 | else |
| 822 | dynamic_paths = nil |
| 823 | end |
| 824 | files.each do |path| |
| 825 | if @pattern |
| 826 | next unless @pattern.match?(path) |
| 827 | end |
| 828 | if dynamic_paths |
| 829 | next unless dynamic_paths.include?(path) |
| 830 | end |
| 831 | output_path = "#{@destination}/#{path}" |
| 832 | yield(output_path) |
| 833 | output_dir = File.dirname(output_path) |
| 834 | FileUtils.mkdir_p(output_dir) |
| 835 | progress_reporter.increment_max |
| 836 | thread_pool << [path, output_path] |
| 837 | end |
| 838 | thread_pool.join |
| 839 | end |
| 840 | progress_reporter.finish |
| 841 | end |