summaryrefslogtreecommitdiff
path: root/app/uploaders/job_artifact_uploader.rb
blob: 8a5200504fc865f011d48c4fa85133704d829ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class JobArtifactUploader < GitlabUploader
  storage :file

  def self.local_artifacts_store
    Gitlab.config.artifacts.path
  end

  def self.artifacts_upload_path
    File.join(self.local_artifacts_store, 'tmp/uploads/')
  end

  def initialize(artifact, _field)
    @artifact = artifact
  end

  def size
    return super if @artifact.size.nil?

    @artifact.size
  end

  def store_dir
    File.join(self.class.local_artifacts_store, default_path)
  end

  private

  def default_path
    creation_date = @artifact.created_at.utc.strftime('%Y_%m_%d')

    File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
              creation_date, @artifact.job_id.to_s, @artifact.id.to_s)
  end

  def disk_hash
    @disk_hash ||= Digest::SHA2.hexdigest(@artifact.project_id.to_s)
  end
end