summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/uploads/helpers.rb
blob: 239cba57297dbf9c3e6363539104f16131659e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module UploadTaskHelpers
  def batch_size
    ENV.fetch('BATCH', 200).to_i
  end

  def calculate_checksum(absolute_path)
    Digest::SHA256.file(absolute_path).hexdigest
  end

  def check_checksum(upload)
    checksum = calculate_checksum(upload.absolute_path)

    if checksum != upload.checksum
      puts "  * File checksum (#{checksum}) does not match the one in the database (#{upload.checksum})".color(:red)
    end
  end

  def uploads_batches(&block)
    Upload.all.in_batches(of: batch_size, start: ENV['ID_FROM'], finish: ENV['ID_TO']) do |relation| # rubocop: disable Cop/InBatches
      yield relation
    end
  end
end