ee/lib/gitlab/geo/transfer.rb
# Use Gitlab::HTTP for now but switch to curb if performance becomes
# an issue
Use Gitlab::HTTP for now but switch to curb if performance becomes
an issue
Use Gitlab :: HTTP for now but switch to curb if performance becomes an issue
def download_file(url, req_headers)
        file_size = -1
        temp_file = open_temp_file(filename)
        return failure unless temp_file
        begin
          response = Gitlab::HTTP.get(url, allow_local_requests: true, headers: req_headers, stream_body: true) do |fragment|
            temp_file.write(fragment)
          end
          temp_file.flush
          unless response.success?
            log_error("Unsuccessful download", filename: filename, response_code: response.code, response_msg: response.try(:msg), url: url)
            return failure(primary_missing_file: primary_missing_file?(response, temp_file))
          end
          if File.directory?(filename)
            log_error("Destination file is a directory", filename: filename)
            return failure
          end
          FileUtils.mv(temp_file.path, filename)
          file_size = File.stat(filename).size
          log_info("Successful downloaded", filename: filename, file_size_bytes: file_size)
        rescue StandardError, Gitlab::HTTP::Error => e
          log_error("Error downloading file", error: e, filename: filename, url: url)
        ensure
          temp_file.close
          temp_file.unlink
        end
        Result.new(success: file_size > -1, bytes_downloaded: [file_size, 0].max)
      end
def download_file ( url , req_headers ) file_size = - 1 temp_file = open_temp_file ( filename ) return failure unless temp_file begin response = Gitlab :: HTTP . get ( url , allow_local_requests : true , headers : req_headers , stream_body : true ) do | fragment | temp_file . write ( fragment ) end temp_file . flush unless response . success? log_error ( "Unsuccessful download" , filename : filename , response_code : response . code , response_msg : response . try ( :msg ) , url : url ) return failure ( primary_missing_file : primary_missing_file? ( response , temp_file ) ) end if File . directory? ( filename ) log_error ( "Destination file is a directory" , filename : filename ) return failure end FileUtils . mv ( temp_file . path , filename ) file_size = File . stat ( filename ) . size log_info ( "Successful downloaded" , filename : filename , file_size_bytes : file_size ) rescue StandardError , Gitlab :: HTTP :: Error => e log_error ( "Error downloading file" , error : e , filename : filename , url : url ) ensure temp_file . close temp_file . unlink end Result . new ( success : file_size > - 1 , bytes_downloaded : [ file_size , 0 ] . max ) end
Use Gitlab::HTTP for now but switch to curb if performance becomes
an issue
Use Gitlab :: HTTP for now but switch to curb if performance becomes an issue
url
<not_specific>
req_headers
<not_specific>