<commit_before>require 'chef/provider/remote_file'

class Chef
  class Provider
    class SharedDownloadHttp < Chef::Provider::RemoteFile

       def action_create
        Chef::Log.debug("#{@new_resource} checking for changes")

        existing_file_checksum = ''
        existing_file_checksum = Chef::Digester.checksum_for_file(@new_resource.path) if ::File.exists?(@new_resource.path)
        puts "existing: #{existing_file_checksum}"
        # value of new checksum changes later on somehow
        desired_checksum = @new_resource.checksum || ''
        puts "desired: #{desired_checksum}"
        if desired_checksum == existing_file_checksum && !existing_file_checksum.empty?
          puts "existing file matches checksum."
          Chef::Log.info("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating")
        else

          mirrors = @new_resource.source.split(",")
          mirrors.each do |mirror|
            begin
              url = URI.parse(mirror)
              url.user, url.password = @new_resource.basic_auth_user, @new_resource.basic_auth_password if @new_resource.basic_auth_user
              Chef::REST.new(mirror, nil, nil).streaming_request(url, @new_resource.headers) do |raw_file|

                raw_checksum = Chef::Digester.checksum_for_file(raw_file.path) if !desired_checksum.empty?
                #lsl = `ls -l #{raw_file.path}`
                #Chef::Log.info("Downloaded file: #{lsl}")
                Chef::Log.info("Downloaded file checksum: #{raw_checksum}")
 
                if desired_checksum.empty? || desired_checksum == raw_checksum
                  Chef::Log.info("Moving to: #{@new_resource.path} ")
                  # not working from java attachment, so using `mv`
                  #FileUtils.cp raw_file.path, @new_resource.path
                  `mv #{raw_file.path} #{@new_resource.path}`
                  lsl = `ls -l #{@new_resource.path}`
                  Chef::Log.info("Downloaded file: #{lsl}")
                else
                  Chef::Log.error("Checksum of downloaded file: #{raw_checksum} expecting: #{@new_resource.checksum}")
                  exit 1
                end
                                
              end

              @new_resource.updated_by_last_action(true)
              # successful download or checksum match
              break
            rescue Exception => e
              Chef::Log.error("got exception downloading: #{mirror} message:"+e.message)
              if e.message == "exit"
                exit 1
              end
            end

          end

        end
        enforce_ownership_and_permissions

        @new_resource.updated_by_last_action?
      end

    end
  end
end<commit_msg>refactor download_http to make it compatible with latest artifact change<commit_after>require 'chef/provider/remote_file'
require 'fileutils'

class Chef
  class Provider
    class SharedDownloadHttp < Chef::Provider::RemoteFile

       def action_create
        Chef::Log.debug("#{@new_resource} checking for changes")

        existing_file_checksum = ''
        existing_file_checksum = Chef::Digester.checksum_for_file(@new_resource.path) if ::File.exists?(@new_resource.path)
        puts "existing: #{existing_file_checksum}"
        # value of new checksum changes later on somehow
        desired_checksum = @new_resource.checksum || ''
        puts "desired: #{desired_checksum}"
        if desired_checksum == existing_file_checksum && !existing_file_checksum.empty?
          puts "existing file matches checksum."
          Chef::Log.info("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating")
        else
          mirrors = @new_resource.source.split(",")
          mirrors.each do |mirror|
            begin
              url = URI.parse(mirror)
              url.user, url.password = @new_resource.basic_auth_user, @new_resource.basic_auth_password if @new_resource.basic_auth_user
              rest = Chef::REST.new(url.to_s,nil, nil, http_client_opts(url.to_s))
              raw_file = rest.streaming_request(url,@new_resource.headers,@new_resource.path)
              raw_checksum = Chef::Digester.checksum_for_file(raw_file.path) if !desired_checksum.empty?

              Chef::Log.info("Downloaded file checksum: #{raw_checksum}")

              if desired_checksum.empty? || desired_checksum == raw_checksum
                Chef::Log.info("Moving to: #{@new_resource.path} ")
                FileUtils.mv(raw_file.path, @new_resource.path)
                Chef::Log.info("Downloaded file: #{@new_resource.path}")
              else
                Chef::Log.error("Checksum of downloaded file: #{raw_checksum} expecting: #{@new_resource.checksum}")
                exit 1
              end
              @new_resource.updated_by_last_action(true)
              # successful download or checksum match
              break
            rescue Exception => e
              Chef::Log.error("got exception downloading: #{mirror} message:"+e.message)
              if e.message == "exit"
                exit 1
              end
            end
          end
        end
        enforce_ownership_and_permissions
        @new_resource.updated_by_last_action?
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10005663583160279, 'fraction_numerical': 0.0007551444213705871, 'mean_word_length': 2.2503067484662576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '932038', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1483, 'n_words': 304}