Class: Gitlab::Ci::ArtifactFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/artifact_file_reader.rb

Constant Summary collapse

Error =
Class.new(StandardError)
TMP_ARTIFACT_EXTRACTION_DIR =
"extracted_artifacts_job_%{id}"

Instance Method Summary collapse

Constructor Details

#initialize(job, max_archive_size:) ⇒ ArtifactFileReader

Returns a new instance of ArtifactFileReader.

Raises:



12
13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/ci/artifact_file_reader.rb', line 12

def initialize(
  job,
  max_archive_size:)
  @job = job
  @max_archive_size = max_archive_size
  raise Error, "Job doesn't exist" unless @job
  raise Error, "Job `#{@job.name}` (#{@job.id}) does not have artifacts" unless @job.artifacts?

  validate!(max_archive_size: max_archive_size)
end

Instance Method Details

#read(path, max_size:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/ci/artifact_file_reader.rb', line 23

def read(path, max_size:)
  @max_file_size = max_size
  return unless job.

   = job.(path)
  file_size = .total_size
  if file_size > max_size
    raise Error,
      "The file `#{path}` in job `#{job.name}` is too large: " \
        "#{bytes_to_human_size(file_size)} " \
        "exceeds maximum of #{bytes_to_human_size(max_size)}"
  end

  read_zip_file!(path)
end